Convert edit_feature into an sp object

40 views Asked by At

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)
0

There are 0 answers