callModule(editMod, ...) only returns the geometry
TiagoOlivoto opened this issue · comments
Hi!
Thanks for the amazing package mapedit!
I use it in my package plimanshiny and I'm facing some difficulties when editing sf objects. In summary, I have an sf object that contains several columns, but after calling callModule(), the returned (edited) sf, only contains the column geometry. Here's a reprex.
library(sf)
library(mapedit)
library(mapview)
library(shiny)
library(leaflet)
library(terra)
df <- st_read(system.file("ex/lux.shp", package="terra"))
ui <- fluidPage(
fluidRow(
# edit module ui
actionButton("editdone", "Done"),
editModUI("editor"),
verbatimTextOutput("out")
)
)
server <- function(input, output, session) {
# edit module returns sf
map <-
mapview()@map |>
addPolygons(
data = df,
weight = 3,
fillColor = "red",
fillOpacity = 1,
group = "editable"
)
edits <- callModule(editMod,
"editor",
map,
targetLayerId = "editable")
observeEvent(input$editdone,{
print(df)
print(edits()$all)
})
}
shinyApp(ui, server)
Here, I removed some polygons. Then, after clicking "Save" and "Done", the output looks like
Simple feature collection with 7 features and 0 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 5.746118 ymin: 49.44781 xmax: 6.516485 ymax: 49.98745
Geodetic CRS: WGS 84
geometry
1 POLYGON ((6.178368 49.87682...
2 POLYGON ((5.881378 49.87015...
3 POLYGON ((6.131309 49.97257...
4 POLYGON ((6.316665 49.62338...
5 POLYGON ((6.425158 49.73164...
6 POLYGON ((5.998312 49.69992...
7 POLYGON ((6.039474 49.44826...
Is this an expected behavior?
How could I obtain the edited sf (with the removed polygons), but keep the original columns (in this case, the columns in df)?