I plotted some plots based on my data, and I use shiny to graph a map and plots to let user select which plot will display, but I got error message:
Warning: Error in <reactive:graphInput>: duplicate 'switch' default value:'"New South...'and'"Victoria"...'
[No stack trace available]
Here are my codes:
region_name <- c("New South Wales","Victoria","Queensland","South Australia","Western Australia","Tasmania",
"Northern Territory","Australian Capital Territory")
ui <- fluidPage(
titlePanel("Agriculture"),
tmapOutput("water_map"),
selectInput("water_graph","Choose a region to graph:",
choices = region_name),
plotOutput("selected_water")
)
## xxx_water_plot is made by ggplot2, and it display correctly without shiny
server <- function(input,output,session){
output$water_map <- renderTmap(water_map)
nsw_water_show <- reactive(nsw_water_plot)
vic_water_show <- reactive(vic_water_plot)
qld_water_show <- reactive(qld_water_plot)
sald_water_show <- reactive(sa_water_plot)
wa_water_show <- reactive(wa_water_plot)
tas_water_show <- reactive(tas_water_plot)
nt_water_show <- reactive(nt_water_plot)
act_water_show <- reactive(act_water_plot)
graphInput <- reactive({
switch(input$water_graph,
"New South Wales" <- nsw_water_show(),
"Victoria" <- vic_water_show(),
"Queensland" <- qld_water_show(),
"South Australia" <- sa_water_show(),
"Western Australia" <- wa_water_show(),
"Tasmania" <- tas_water_show(),
"Northern Territory" <- nt_water_show(),
"Australia Capital Territory" <- act_water_show()
)
})
output$selected_water <- renderPlot({
graphInput()
})
}
I don't know what the problem is, the tmap displays correctly, and the selection is in the correct position as I thought, but the plot doesn't show up. I don't understand the error message, there should not be any duplicate values in selection. Can anyone help me? Thanks.