This is the code I have so far
library(shiny)
NJData <- data.frame("Year" = c(2000, 2000, 2001, 2001, 2002, 2002, 2003, 2003),
"WUCode" = c("IR", "PS", "IR", "PS","IR", "PS","IR", "PS"), Annual.Value" = c(12, 14,
19, 7, 11, 13, 20, 17))
ui <- fluidPage(
titlePanel("Subsetting Dataset"),
sidebarLayout(
sidebarPanel(
selectInput("codeInput1", label = "Choose Year", choices = unique(NJData$Year)),
selectInput("codeInput2", label = "Choose WU Type", choices = unique(NJData$WUCode))
),
mainPanel(
tableOutput("view")
)
)
)
server <- function(input, output) {
dataset <- reactive({
return(subset(NJData, (Year == input$codeInput1 & Water.Use.Subtype.Code ==
input$codeInput2)))
})
#output$view <- renderTable(dataset())
output$plot <- renderPlot({
p<-ggplot(dataset(),
aes_string(
x = dataset()$Year,
y = dataset()$Annual.Value,
fill = dataset()$Year # let type determine plotting
)
)
})
}
shinyApp(ui = ui, server = server)
I want to allow the user to choose what year and what WU type to use and then generate a boxplot of the Annual Value for that year and WU type, but I can't get the boxplot to generate.
Any help is greatly appreciated!