Last active
November 18, 2016 09:13
-
-
Save endlesspint8/dc42163817bd73ca5f2a606c5ff6699f 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_sdd.csv") | |
shinyServer(function(input, output) { | |
output$plot <- renderPlot({ | |
Xax <- switch(input$xaxis, | |
'ABV' = cb_data$abv_sdd, | |
'IBU (bitterness)' = cb_data$ibu_sdd, | |
'SRM (color)' = cb_data$srm_sdd, | |
'Temperature (recommended)' = cb_data$temp_sdd) | |
Yax <- switch(input$yaxis, | |
'ABV' = cb_data$abv_sdd, | |
'IBU (bitterness)' = cb_data$ibu_sdd, | |
'SRM (color)' = cb_data$srm_sdd, | |
'Temperature (recommended)' = cb_data$temp_sdd) | |
Cat <- switch(input$group, | |
'Category' = cb_data$category, | |
'Glass' = cb_data$glass, | |
'Yeast' = cb_data$Yeast) | |
.e <- environment() | |
p <- ggplot(cb_data, aes(Xax, Yax), environment = .e) + | |
geom_point(aes(color=Cat), size = 3) + | |
labs(title='Standardized Feature Comparison\n', | |
x=input$xaxis, y=paste(input$yaxis, '\n', sep='')) + | |
theme(aspect.ratio = 1) + | |
theme(legend.title = element_blank()) | |
# 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()) | |
if (input$checkbox == TRUE) { | |
print(p + geom_smooth()) | |
} | |
else { | |
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("craftbeerExplore2")), | |
helpText("Select two measures, a grouping, and | |
whether you want to smooth when updating the graph."), | |
selectInput('xaxis', | |
label='X Axis', | |
choices=c('ABV', 'IBU (bitterness)', 'SRM (color)', 'Temperature (recommended)'), | |
selected='IBU (bitterness)'), | |
selectInput('yaxis', | |
label='Y Axis', | |
choices=c('ABV', 'IBU (bitterness)', 'SRM (color)', 'Temperature (recommended)'), | |
selected='ABV'), | |
selectInput('group', | |
label='Color By:', | |
choices=c('None', 'Category', 'Glass', 'Yeast'), | |
selected='None'), | |
checkboxInput("checkbox", label = "Smooth", value = FALSE), | |
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