Can I access the Shiny R Leaflet controls (outside the leaflet)?

I am working on creating a Shiny / Leaflet application similar to this, which is done in the table . It shows world views on poverty in different years, allowing the user to filter the map by variable, region and year.

The problem is that the global shapefile at the country level (from NaturalEarthData) appears rather slowly. I work on different ways to simplify these polygons to reduce load times, but in the meantime I am working on other potential solutions.

Ideally, I would use Shiny controls to switch different layers of the map and use leafletProxyto update the map. But as each layer changes the entire map again, it is also rather slow.

When I include different layers inside the Leaflet, the layers appear much, much faster. (I assume that this is due to the fact that the parameter addLayersControlin the "Leaflet" changes the fillColorpolygons, and does not redraw the entire global shapefile, as is done using leafletProxy). But is there a way to access these layers outside of the Flyer?

To illustrate here, here is some dummy code:

#load required libraries 
library(shiny)
library(leaflet)
library(raster)

#begin shiny app
shinyApp(

  ui <- fluidPage(
    leafletOutput("map", width = "100%", height = 600) 
  ), #END UI

  server <- function(input, output, session){

    #load shapefile
    rwa <- getData("GADM", country = "RWA", level = 0)

    #render map
    output$map <- renderLeaflet({
      leaflet() %>% 
        addTiles() %>% 
        addPolygons(data = rwa, 
                    fillColor = "blue", 
                    group = "blue") %>% 
        addPolygons(data = rwa, 
                    fillColor = "red", 
                    group = "red") %>% 
        addLayersControl(baseGroups = c("blue", "red"), 
                         options = layersControlOptions(collapsed = F))
    }) #END RENDER LEAFLET 
  } #END SERVER
) #END SHINY APP

Which has the following output: enter image description here

. , , Shiny table , . , Shiny observeEvent. / ?

+4

Source: https://habr.com/ru/post/1665761/


All Articles