I\'m working on a tool with shiny and leaflet: I want that when a customer click on the vars (see UI code for exemple NE), the map go to another view for exemple like this in pu
To update a leafletMap you should use leafletProxy
, you can read about that here.
The idea is that you need to have a reactive
value that is updated when you change the selection, that reactive
value is observed by the leafletProxy
and its values used to perform the update.
It should look like this:
output$map <- renderLeaflet({
leaflet(data) %>%
addTiles(urlTemplate = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
attribution = 'Maps by <a href="http://www.mapbox.com/">Mapbox</a>'
) %>%
setView(lng = 6.6328200, lat = 46.5160000, zoom = 12) %>%
addMarkers(data$long, data$lat, label = data$nom)
})
center <- reactive({
subset(data, nom == input$canton)
# or whatever operation is needed to transform the selection
# to an object that contains lat and long
})
observe({
leafletProxy('map') %>%
setView(lng = center()$long, lat = center()$lat, zoom = 12)
})