if (FALSE) {
# In a Shiny application
library(shiny)
library(mapgl)
ui <- fluidPage(
mapboxglOutput("map"),
actionButton("clear_btn", "Clear Drawn Features")
)
server <- function(input, output, session) {
output$map <- renderMapboxgl({
mapboxgl(
style = mapbox_style("streets"),
center = c(-74.50, 40),
zoom = 9
) |>
add_draw_control()
})
observeEvent(input$clear_btn, {
mapboxgl_proxy("map") |>
clear_drawn_features()
})
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab