Trying to create a shiny app that has a dropdown menu allowing you to select plots that are subelements of a list that is saved to the global environment.
The plots are located in the second subelement of each element in a list
e.g. list = ([[dataframe1, plot1], [dataframe2, plot2], etc])
The app I am trying to create is given by:
choices = paste0("list[[1]][[", 1:2, "]]")
ui <- shinyUI(fluidPage(selectInput("selectPlot",
"Choose desired country",
choices),
plotlyOutput("plot")))
server <- shinyServer(function(input,output){
output$plot <- renderPlotly({
return(get(input$selectPlot))
})
})
shinyApp(ui,server)
However, no plots are being shown and I am receiving the following error: **Warning: Error in get: object 'anom[[1]][[1]]' not found*
If I save the plots individually to the environment then this approach works. However, I am trying to access the plots via this list that is already present!
Adding reproducible example:
ds1 <- data.frame(sample(1:10, 10), sample(11:20, 10))
ds2 <- data.frame(sample(1:10, 10), sample(11:20, 10))
p1 = plot_ly(x = ~ds1[[1]], y = ~ds1[[2]]) %>% add_markers()
p2 = plot_ly(x = ~ds2[[1]], y = ~ds2[[2]]) %>% add_markers()
l = list(list(ds1, p1), list(ds2, p2))
#want to access p1 and p2 from within the list to create drop down menu graph
choices.p = paste0("l[[1]][[", 1:2, "]]")
ui <- shinyUI(fluidPage(selectInput("selectPlot",
"Choose desired country",
choices.p),
plotlyOutput("plot")))
server <- shinyServer(function(input,output){
output$plot <- renderPlotly({
return(get(input$selectPlot))
})
})
shinyApp(ui,server)