If we just take a standard leaflet
map like the one below:
library(leaflet)
library(maps)
mapStates = map("state", fill = TRUE, plot = FALSE)
leaflet(data = mapStates) %>% addTiles() %>%
addPolygons(fillColor = topo.colors(10, alpha = NULL), stroke = FALSE)
Is there a way to add a button that adds and removes certain polygons? For example, if the map above contained several layers (i.e. uninsured rates & average age), I would want a button or toggle switch that would allow a user to add and remove all states that begin with "a" (silly example). So instead of having 4 layers (two with those statistics across all states and two with those statistics across the states that do not begin with "a"), I would only have two layers and a button.
My caveat is that it needs to be exportable in .html format, which means I cannot deploy a shiny
solution.
Perhaps there's an addEasyButton
solution?