rmapdeck

Clearing data while maintaining the same view in mapdeck/mapbox in R


I'm using mapdeck in conjunction with shiny to create an interactive map with various interactive filters for the data. One input that I want to include is an input that toggles on/off a certain layer of data (bus stations). This is the code I have in the server portion of my shiny app for this specific widget:

  observeEvent({input$stations} {
    if(input$stations == 0){
      mapdeck_update(map_id = "myMap") %>%
        clear_scatterplot(layer_id = "bus_stations")
        
    }  
    
    if(input$stations == 1){
      mapdeck_update(map_id = "myMap") %>%
        add_scatterplot(
          data = stations
          , layer_id = "bus_stations"
          , update_view = FALSE
        )
    }
  })

For the input, a value of 0 indicates that the stations layer should be off, while a value of 1 should keep the stations layer on. The code works as is, however, my issue is that the map updates its view every time an input of 0 is selected, as there is no argument allowing you to set update_view = FALSE in the parameters for clear_scatterplot. I want the map view to remain constant whenever someone toggles this input - is there a way to do this using mapdeck in R?


Solution

  • The various clear_() functions get the update_view argument from v0.3.5. As of today (4th June 2021) this is not on CRAN and should be installed from github

    remotes::install_github("SymbolixAU/mapdeck")
    

    With 0.3.5 installed you can now call

    clear_scatterplot(layer_id = "bus_stations", update_view = FALSE)