if (FALSE) {
library(mapgl)
library(tigris)
# Add features from an existing source
tx <- counties(state = "TX", cb = TRUE)
mapboxgl(bounds = tx) |>
add_source(id = "tx", data = tx) |>
add_draw_control() |>
add_features_to_draw(source = "tx")
# In a Shiny app
observeEvent(input$load_data, {
mapboxgl_proxy("map") |>
add_features_to_draw(
source = "dynamic_data",
clear_existing = TRUE
)
})
}
Run the code above in your browser using DataLab