Hi everyone,
I would like to figure out how to use editMod (Shiny modules present in mapedit package) to edit a set of polygons already that are already present in the app or that are called from a database.
That is, I would like to allow the user to be able to edit polygons already in the app or delete them or add more.
I will attach the r code that i am using.
Thanks in advance for everyone who will help me solve this problem.
library(shiny)
library(mapview)
library(mapedit)
library(leafem)
library(sf)
ui <- fluidPage(
editModUI("editMod_UI"),
actionButton("save_polygons",
label="Save the modified polygons"),
mapviewOutput(outputId = "new_polygons")
)
server <- function(input, output) {
franconia<-franconia
edits <- callModule(editMod,
"editMod_UI",
leaflet() %>% addFeatures(franconia))
observeEvent(input$save_polygons, {
polygon<-edits()$finished
polygon<-st_as_sf(polygon)
output$new_polygons<-renderMapview({
mapview(polygon)
})
})
}
shinyApp(ui = ui, server = server)