Last active
November 18, 2016 09:13
-
-
Save endlesspint8/83e1a4d68527e4b73a93a96c30b0edf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R Shiny code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# server.R template | |
library(ggplot2) | |
library(shiny) | |
cb_data <- read.csv("data/cb_shiny.csv") | |
shinyServer(function(input, output) { | |
output$plot <- renderPlot({ | |
Xax <- switch(input$xaxis, | |
'Category' = cb_data$category, | |
'Glass' = cb_data$glass, | |
'Yeast' = cb_data$Yeast) | |
Yax <- switch(input$yaxis, | |
'ABV' = cb_data$abv_avg, | |
'IBU (bitterness)' = cb_data$ibu_avg, | |
'SRM (color)' = cb_data$srm_avg, | |
'Temperature (recommended)' = cb_data$temp_avg) | |
#boxplot(y~x, data=cb_data) | |
.e <- environment() | |
p <- ggplot(cb_data, aes(Xax, Yax), environment = .e) + | |
geom_boxplot(aes(color=Xax)) + | |
labs(title='Feature Comparison\n', x=input$xaxis, y=paste(input$yaxis, '\n', sep='')) + | |
theme(axis.text.x = element_text(angle = 45, hjust=1.0, vjust=1.0, size=12)) + | |
theme(legend.title = element_blank()) | |
print(p) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ui.R template | |
library(ggplot2) | |
library(shiny) | |
shinyUI(fluidPage( | |
tags$head(includeScript("google-analytics.js")), | |
titlePanel(a(href = "http://www.endlesspint.com", style = "color:black", "endlesspint")), | |
sidebarLayout( | |
sidebarPanel( | |
h3(strong("craftbeerExplore")), | |
p("Select a category and a measure to update the graph."), | |
selectInput('xaxis', | |
label='Grouping', | |
choices=c('Category', 'Glass', 'Yeast'), | |
selected='Category'), | |
selectInput('yaxis', | |
label='Measure', | |
choices=c('ABV', 'IBU (bitterness)', 'SRM (color)', 'Temperature (recommended)'), | |
selected='ABV'), | |
br(), | |
"Data Source:", a(href = "http://www.craftbeer.com/beer-styles", target = "_blank", style = "color:black", "CraftBeer.com") | |
), | |
mainPanel(plotOutput("plot")) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment