Neal V. Quizon
February 14, 2019
Overview
This is an RStudio shiny application developed as a part of final project in the Developing Data Products course in Coursera Data Science Specialization track. The application is a boxplot of the cylinders, transmission and engine of the Mtcars data.
The project includes checkbox for option of showing outliers. Also, option of the desired variable of the boxplot in the Mtcars data.
Application widgets used
This application uses widgets: checkbox and textbox.
This is hosted in the following site: https://haskellneal.shinyapps.io/CourseProjectDDPWeek4/
Application - ui.R
library(shiny)
# Define UI for miles per gallon app ----
ui <- fluidPage(
# App title ----
titlePanel("Miles Per Gallon"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for variable to plot against mpg ----
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Engine" = "vs")),
# Input: Checkbox for whether outliers should be included ----
checkboxInput("outliers", "Show outliers", TRUE)
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Formatted text for caption ----
h3(textOutput("caption")),
# Output: Plot of the requested variable against mpg ----
plotOutput("mpgPlot")
)
)
)
Application - server.R
# Define server logic to plot various variables against mpg ----
server <- function(input, output) {
mpgData <- mtcars
mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))
mpgData$vs <- factor(mpgData$vs, labels = c("V-shaped", "straight"))
# Compute the formula text ----
# This is in a reactive expression since it is shared by the
# output$caption and output$mpgPlot functions
formulaText <- reactive({
paste("mpg ~", input$variable)
})
# Return the formula text for printing as a caption ----
output$caption <- renderText({
formulaText()
})
# Generate a plot of the requested variable against mpg ----
# and only exclude outliers if requested
output$mpgPlot <- renderPlot({
boxplot(as.formula(formulaText()),
data = mpgData,
outline = input$outliers,
col = "#75AADB", pch = 19)
})
}
# Run the application
shinyApp(ui = ui, server = server)