inst/examples/styleeditor.R

library(shiny)
library(leaflet)
library(leaflet.extras)

ui <- fluidPage(
  actionButton("rem", "Remove")
  , leafletOutput("map", height = 800)
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>%
      setView(0, 0, 2) %>%
      addProviderTiles(providers$CartoDB.Positron) %>%
      addDrawToolbar(
        targetGroup = "draw",
        editOptions = editToolbarOptions(selectedPathOptions = selectedPathOptions())
      ) %>%
      addLayersControl(
        overlayGroups = c("draw"), options = layersControlOptions(collapsed = FALSE)
      ) %>%
      # add the style editor to alter shapes added to map
      addStyleEditor()
  })

  observeEvent(input$rem, {
    leafletProxy("map") %>%
      removeStyleEditor()
  })
}
shinyApp(ui, server)

Try the leaflet.extras package in your browser

Any scripts or data that you put into this service are public.

leaflet.extras documentation built on Sept. 11, 2024, 7:54 p.m.