Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callModule(editMod, ...) only returns the geometry #132

Open
TiagoOlivoto opened this issue Feb 7, 2024 · 0 comments
Open

callModule(editMod, ...) only returns the geometry #132

TiagoOlivoto opened this issue Feb 7, 2024 · 0 comments

Comments

@TiagoOlivoto
Copy link

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)

image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant