I want to make a map using leaflet in shiny with a checkboxGroupInput inside the map and use the inputs of the checkboxGroupInput to update the data that is used to make the map. But I don't know how to use those inputs, I tried the code below but it didn't work. I would aprecciate any advice.
library(shiny)
library(leaflet)
df <- data.frame(
cat = sample(letters[1:3],10, replace = TRUE),
long = runif(10,60,100),
lat = runif(10,40,60)
)
ui <- fluidPage(
leafletOutput("map1")
)
server <- function(input, output, session) {
output$map1 <- renderLeaflet({
leaflet(df %>% filter(cat %in% input$x))%>%
addTiles() %>%
addMarkers(~long,~lat) %>%
addControl(checkboxGroupInput(inputId = 'x',
'Select cat',
unique(df$cat)))
})
}
shinyApp(ui, server)