1

Drawing a polygon using R leaflet, how can the drawn object be converted into an sp object? The goal is to use it for filtering spatial points.

library(leaflet.extras)
library(sp)
library(geojsonio)

# Define UI 
ui <- fluidPage(
  useShinyjs(),
  leafletOutput("mymap",height=800)
)

# Define server logic 
server <- function(input, output) {

  output$mymap <- renderLeaflet(
    leaflet() %>%
      addTiles() %>%
      addDrawToolbar()
    )

  observeEvent(input$mymap_draw_new_feature,{
    feature <- input$mymap_draw_new_feature

    # convert feature into sp object - this fails
    feature_sp <- geojsonio::geojson_sp(feature)

  })

}

# Run the application
shinyApp(ui = ui, server = server)
zx8754
  • 52,746
  • 12
  • 114
  • 209
Vlad
  • 3,058
  • 4
  • 25
  • 53
  • Can you create a minimal reproducible example? There's no need for a shiny shell. If you have a question on converting data, provide needed packages, data and code you've tried to work it out. – Roman Luštrik Sep 24 '19 at 07:27
  • Actually I'm not sure how to do that - setting the leaflet map to a variable is fine, but then how to save the new_feature? It is easy enough with `mapedit` package, however I'm not using it as it is missing some functionality I need for Shiny. – Vlad Sep 24 '19 at 08:14

0 Answers0