Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library("shiny")
- library("ggplot2")
- library("DT")
- library("reshape2")
- ## load data ##
- aqi = read.csv(file = "C:/Users/stan/Desktop/AIR/month.csv",
- header = T, sep = ",")
- str(aqi)
- colnames(aqi) = c("num","month",
- "PM10","PM2.5","NO","NO2")
- ## ui.R ##
- ui = fluidPage(
- titlePanel('AIR'),
- sidebarLayout(
- sidebarPanel(
- selectInput('month',
- 'Choose a month:',
- c('All', unique(as.character(aqi$month)
- ))),
- selectInput('PM10',
- 'Number of :PM10',
- c('All', unique(as.character(aqi$PM10)
- ))),
- selectInput('PM2.5',
- 'Number of PM2.5:',
- c('All',unique(as.character(aqi$PM2.5)
- ))),
- selectizeInput("AIR",
- "Select Contaminant:",
- choices = c( "PM2.5",
- "PM10"),
- selected = "PM2..5",
- multiple = TRUE )
- ),
- mainPanel(
- dataTableOutput('table'),
- plotOutput("plot")
- )
- )
- )
- ## server.R ##
- server = function(input, output) {
- # Filter data based on selections
- output$table <- DT::renderDataTable(DT::datatable({
- data <- aqi
- if (input$month != "All") {
- data <- data[aqi$month == input$month,]
- }
- if (input$PM10 != "All") {
- data <- data[aqi$PM10 == input$PM10,]
- }
- data
- if (input$PM2.5 != "All") {
- data <- data[aqi$PM2.5 == input$PM2.5,]
- }
- data
- }))
- output$plot = renderPlot({
- plot.data <- melt(aqi, id.vars= "month")
- #not sure if input$cnt is a list or a vector
- #may need to manipulate that before passing
- plot.data <- plot.data[plot.data$variable %in% input$AIR, ]
- ggplot(plot.data) +
- geom_line(mapping = aes(x = month, y = value , colour =variable)) +
- labs (x = "month", y = "value", title = "AIR") +
- scale_colour_discrete(name = "AIR")
- })
- }
- shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement