I am developing a dashboard in Rmarkdown
, Flexdashboard
and Shiny
. At the moment I am using Leaflet
to map several points and I have a shiny input, which when pressing a button selects a certain point and zooms it.
I would like to know if there is a way to control the zoom speed.
An example in pictures:
Initial state of the map, the points are in blue.
Panel where the user selects the point and the button executes the filtering and zooming.
In this image I show the zoom to the selected point, which is very fast.
I leave some example code and I remain attentive to your comments. Thank you.
{r chunk, echo = false}
leafletOutput(outputId = "mapa1")
# DATA FILTERED BY USER INPUT (1 point)
rbdFiltered <- reactive({
misDatos()[misDatos()$rdb == input$rbd, ]
})
# LEAFLET OBJECT WITH ALL POINTS
myMap <- reactive({
input$params
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = misDatos(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
setView(lng = -70.560946, lat = -33.592340, zoom = 13) # ZOOM SET HERE
})
# OBSERVE EVENT (Select a point)
observeEvent(input$BT_select_rbd, {
leafletProxy(mapId = "mapa1") %>% clearGroup(group = "myMarkers") %>%
addCircleMarkers(data = rbdFiltered(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
# HERE A ZOOM TO THE SELECTED POINT IS PROCESSED, IS IT POSSIBLE TO CONTROL THE SPEED?
setView(lng = rbdFiltered()$longitud, lat = rbdFiltered()$latitud, zoom = 17)
})
# OBSERVE EVENT (Show all points)
observeEvent(input$BT_todo_rbd, {
leafletProxy(mapId = "mapa1") %>% clearGroup(group = "myMarkers") %>%
addCircleMarkers(data = misDatos(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
setView(lng = -70.560946, lat = -33.592340, zoom = 13) # WE RETURN TO ORIGINAL ZOOM
})
output$mapa1 <- renderLeaflet({myMap()})
Regards EDITED: Images