Juliet Nantege
9/22/2017
This app allows you to view a graph of New York temperature by day of month in the period specified in title above. The airquality data in the datasets package was used to generate this report. First we will walk through the steps and code used to build the app.
Open shiny in R studio
Write code as displayed in next slide on the ui.R page
Write code as displayed on slide four in the server.R page
Save and run
library(shiny)
shinyUI(fluidPage(
titlePanel("New York Temperature (May to September 1973)"),
sidebarLayout(
sidebarPanel(
sliderInput("slider", "Use slider below to choose consecutive days of month from 1 - 31", 1, 31, value = c(1,31)),
checkboxInput ("Show_Title", "show/hide Title", value = TRUE)
),
mainPanel(
h3("The graph"),
plotOutput("Plot")
)
)
))
<!–html_preserve–>
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
output$Plot <- renderPlot({
min <- input$slider[1]
max <- input$slider[2]
levels(airquality$Month) <- c("May", "June", "July", "Aug", "Sep")
data <- subset(airquality, Day %in% min:max)
title <- ifelse(input$Show_Title, "Temperature by day of the month", "")
ggplot(data, aes(Day, Temp, col = Month)) + geom_line() + facet_grid(Month ~.) +
xlab("Day of month") + ylab("Temperature") +ggtitle(title)
})
})
The graph below will be displayed by the app and can be edited using the generated widgets in sidebar.