Hi,
I just start with R markdown
, I search a solution to my issue on several topics but I could not find it. I have a dataset containing several observations of several species (referenced with Longitude and Latitude), and I try to make an interactive page (to share in html after with some people), in which we could select the species of interest through a menu, and obtain automatically the corresponding map of observations from the selectInput value. However, I could not find how to make the map appearing automatically after selecting the species in the menu.
I created a list (list_map
) of the length of the number of species. Each list object is the map of each species, as a plotly
object to get interactive maps. In the list, each map is named from the codename of the species.
Then, in my code, I did a menu to select the species of interest:
``` {r, echo = FALSE}
selectInput(inputId = "sp_choice", label = "Select a species",
choices = names(list_map))```
```{r, echo = FALSE}
renderUI({
HTML(paste("You selected", input$sp_choice))
})```
This works, and for example, I selected in the menu the species "UnOb", and now I would like to automatically plot the corresponding ggplotly map from list_map
(which is the object list_map$"UnOb"
).
However, I can't find how to make the corresponding plot appearing automatically. I tried several codes but I think I am not fully understanding how all of these work...
For example, the code above seems to almost work, it opened another window once but then my computer did not stop charging something that never appeared...
ui <- fluidPage(
selectInput(inputId = "sp_choice", label = "Select a species",
choices = names(list_map)),
renderUI({
HTML(paste("You selected", input$sp_choice))
}),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
print(list_map[names(list_map) %in% input$sp_choice])
})
}
shinyApp(ui, server)
Thanks a lot in advance for your help!