Created
April 5, 2018 20:18
-
-
Save jasdumas/3eb7d8210e924be221ae6e492ea6d6b8 to your computer and use it in GitHub Desktop.
A better way to include logos in the comments # (also inspired from here: https://stackoverflow.com/a/21997097/4143444)
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
library(shiny) | |
library(ttbbeer) | |
data("beermaterials") | |
library(tidyverse) | |
library(ggridges) | |
library(shinythemes) | |
library(wesanderson) | |
library(shinyLP) | |
library(scales) | |
# Define UI for application | |
ui <- navbarPage( | |
#################### | |
title = tags$header("Historical U.S. Beer Materials", | |
# this image should be in your www/ folder | |
tags$img(src='beer-logo.png', | |
# "left" makes the logo the farest edge | |
align = "right", | |
style = "text-decoration:none; | |
border: 0; | |
margin: 0; | |
padding: 0px; | |
left: 0px; | |
# this helped center the image once it was re-sized | |
top: -16px; | |
position: relative;")), | |
#################### | |
theme = shinytheme("journal"), | |
inverse = T, | |
tabPanel("Introduction", icon = icon("home"), | |
jumbotron(header = "Analyzing & Modeling Historical U.S. Beer Materials", content = "", button = F), | |
fluidRow( | |
column(6, panel_div(class_type = "primary", panel_title = "How to use this app?", | |
content = "Explore the data visualzations to develop insights about the distribution of the ingredients used in beer production over time. Interpret the time series model to answer questions about predicting future beer materials usage.")), | |
column(6, panel_div("success", "Application Maintainers", | |
HTML("Email the: <a href='mailto:name@hi.com?Subject=Shiny%20Help' target='_top'>App Developer</a> with questions about bugs. or submit a issue"))) | |
), # end of fluidRow | |
fluidRow( | |
column(6, panel_div("info", "App Status", "In-development during DataCamp course. Future versions will include updated data from the U.S. Treasury TTB portal as posted!")), | |
column(6, panel_div("danger", "Security and License", "Copyright 2017")) | |
) # end of fluidRow | |
), | |
tabPanel("Exploratory Data Analysis", icon = icon("area-chart"), | |
tags$head( | |
tags$style(HTML(" | |
@import url('//fonts.googleapis.com/css?family=Indie+Flower|Cabin:400,700'); | |
h2 { | |
font-family: 'Indie Flower', cursive; | |
font-weight: 500; | |
line-height: 1.3; | |
color: #E8DE2A; | |
} | |
")) | |
), | |
# Sidebar with a slider input for production year | |
sidebarLayout( | |
sidebarPanel( | |
sliderInput("year", | |
"Production Year:", | |
min = 2006, | |
max = 2015, | |
value = 2008, | |
animate = T, | |
step = 1, | |
sep = "") | |
), | |
# Show a plot of the generated distribution | |
mainPanel( | |
fluidRow( | |
column(6, | |
h2("Introduction to beer data"), | |
p("The data displayed below is from the R package ", tags$a(href="https://github.com/jasdumas/ttbbeer", code("ttbbeer"))), | |
p(HTML("<a href='https://cran.r-project.org/package=ttbbeer' class='btn btn-info' role='button'>See more</a>")) | |
), | |
column(6, | |
h2("Visualizing the data"), | |
p("Joyplots are partially overlapping line plots that create the impression of a mountain range."), | |
p(HTML("<a href='https://cran.r-project.org/web/packages/ggridges/vignettes/introduction.html' class='btn btn-primary' role='button'>See more</a>")) | |
) | |
), | |
wells(content = "Press the red triangular 'play' button on the year slider to loop through the years."), | |
plotOutput("distPlot") | |
) | |
) | |
), # end of tabPanel | |
tabPanel("Modeling", icon = icon("beer")) | |
) # end of ui | |
# Define server logic | |
server <- function(input, output) { | |
# data cleaning reactive | |
bm_df <- reactive({ | |
# tidy the data | |
names(beermaterials) <- c("month", "year", "malt", "corn", "rice", "barley", "wheat", "sugar", "hops_dry", "hops_extract", "other") | |
beermaterials <- gather(beermaterials, key = material, value = pounds, -month, -year) | |
# subset data by year | |
bm_df <- beermaterials[beermaterials$year == input$year, ] | |
}) | |
output$distPlot <- renderPlot({ | |
# plot joy plots | |
ggplot(bm_df(), aes(x = pounds, y = material, fill = material)) + | |
geom_density_ridges() + | |
theme_ridges(grid = FALSE) + | |
guides(fill=FALSE) + | |
labs(title = paste0("U.S. Beer Materials in ", input$year), y="", x="pounds (log scale)") + | |
scale_fill_manual(values = wes_palette("Zissou1", 9, type = "continuous")) + | |
#scale_x_continuous(label=unit_format("K")) + | |
scale_x_log10(label=unit_format("K")) | |
}) | |
} | |
# Run the application | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment