Shiny Application and Reproducible Pitch
Author: Zhenning Xu
Date: June 30th, 2019
There are two parts in this project: a Shiny application and deploy it on Rstudio's servers and a reproducible pitch presentation prepared by Slidify or Rstudio Presenter about the Shiny application.
The app developed for the first part of the assignment demo is avalilable at: https://utjimmyx.shinyapps.io/ShinyBCLiquor/
The Shiny application created for this project is an interactive web app using the BC Liquor dataset. The web app offers a easy-to-use interface for consumers to explore the products available at the BC Liquor Store.This is just a simple demo of the Shiny App. If you are really into this, you may also explore a more advanced app available at the Google Play Store or the Apple App Store: https://play.google.com/store/apps/details?id=com.xomodigital.bcliquor&hl=en_US https://apps.apple.com/nz/app/bc-liquor-stores/id437904986
The data used in the app comes from the the BC Liquor dataset. Let's take a look at the head of the dataset and the code:
setwd("C:/Users/xzhenning/Documents/R/shiny")
bcl<-read.csv("bcl-data.csv",stringsAsFactors = FALSE)
head(bcl)
library(shiny)
ui <- fluidPage(
titlePanel("BC Liquor Store prices"),
sidebarLayout(
sidebarPanel(
sliderInput("priceInput", "Price", 0, 100, c(25, 40), pre = "$"),
radioButtons("typeInput", "Product type",
choices = c("BEER", "REFRESHMENT", "SPIRITS", "WINE"),
selected = "WINE"),
selectInput("countryInput", "Country",
choices = c("CANADA", "FRANCE", "ITALY"))
),
mainPanel(
plotOutput("coolplot"),
br(), br(),
tableOutput("results")
)
)
)
Use a temporary reactive value for the filtered data according to your dropdown. Then use the filtered data for the plot. The interactive dashboard allows you to choose your desired liquor based on a few characteristics: product type, price, country of origin, alcohol content, and sweetness.
server <- function(input, output) {
output$coolplot <- renderPlot({
filtered <-
bcl %>%
filter(Price >= input$priceInput[1],
Price <= input$priceInput[2],
Type == input$typeInput,
Country == input$countryInput
)
ggplot(filtered, aes(Alcohol_Content)) +
geom_histogram(fill = "black") +
theme(plot.background = element_rect(color = "green", fill = "pink", size = 6))
}) #you can customize the color of the bins easily using the color code options
}
shinyApp(ui = ui, server = server)
The primary output displayed on my shiny site (https://utjimmyx.shinyapps.io/ShinyBCLiquor/) consists of a slider for alcohol content, a radio button for you to choose the type of alcohol (to ensure like-for-like comparison) and a drop down menu to choose the country of origin.
Let's capture the Shiny app using the webshot package
Reference: https://bookdown.org/yihui/bookdown/web-pages-and-shiny-apps.html