3

I am creating a map app with shiny. I'm looking for a way to delete a polygon created with addDrawToolbar using the actionButton placed on the sidebar. The sample code is as follows.

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

ui <- fluidPage(
  titlePanel("ShinyApp"),
  sidebarLayout(
    sidebarPanel(
      actionButton("delete","DELETE"),
    ),
    mainPanel(
      leafletOutput('maps')
    )
  )
)

server <- function(input, output, session) {
  
  output$maps <- renderLeaflet({leaflet()%>%addTiles()%>%
      addDrawToolbar(
        targetGroup='draw',
        editOptions = editToolbarOptions(selectedPathOptions = selectedPathOptions()),
        rectangleOptions = F, 
        polylineOptions = F, 
        markerOptions = F, 
        circleOptions=F,
        circleMarkerOptions=F)
    })
  
  observeEvent(input$delete, {
    
    #process
    leafletProxy("maps")%>%
      removeDrawToolbar(clearFeatures=TRUE)
  })

}
shinyApp(ui, server)

It is stated on the net that it can be deleted by using removeDrawToolbar (clearFeatures = TRUE), but it could not be realized.

If anyone knows or has a web page that can be used as a reference, I would be grateful if you could let me know.

ken iwa
  • 171
  • 8
  • You must be working on something big, ken. There is this issure on github: https://github.com/bhaskarvk/leaflet.extras/issues/148 – mrhellmann Dec 25 '20 at 03:34
  • Thank you very much for your answers every time.Currently, I am developing a WebGIS application using Shiny.There are many things I don't understand, so I'm using stackoverflow.Thank you for introducing the web page. Of similar pages https://github.com/bhaskarvk/leaflet.extras/pull/184 The solution was written in. remotes :: install_github ("bhaskarvk / leaflet.extras", ref = remotes :: github_pull ("184")) By doing, I was able to delete the polygon. – ken iwa Dec 25 '20 at 05:05
  • Trying to install from `184` no longer works... I think because the repository is archived? Anyway, there are forks that incorporate the changes so you can use those instead e.g. `remotes::install_github("micahwilhelm/leaflet.extras")` – smartse Aug 16 '23 at 14:30

0 Answers0