Reputation: 1
This is a crosspost from the mapedit
issues github page here. I am attempting to build a shiny app that allows a user to plot a subset of data after selecting polygons using the mapedit
package. While I am able to successfully plot the data using mapedit
, I am unable to flush the $finished
data after the selected mapedit polygons are deleted.
This produces two errors that I have yet to determine a workaround for, 1) if the plot collapses as seen in the gif below an error the argument is of length zero
, and 2) if the plot does not collapse, the last selected $finished
data remains with no ability to clear the data from the plot.
Is there anything that can be done to solve these issues? This primarily occurs when more than two polygons are drawn and then deleted. While I thought there would be a reactive workaround, I have not been successful thus far.
Below is a reproducible example from r-spatial blog mapedit - updates in 0.2.0. In my shiny app I am using the mapedit package to subset a different time series using object ids and plot a timeseries in plotly. I believe the underlying issue can be solved using the reproducible example below.
library(sf)
# make the coordinates a numeric matrix
qk_mx <- data.matrix(quakes[,2:1])
# convert the coordinates to a multipoint feature
qk_mp <- st_multipoint(qk_mx)
# convert the multipoint feature to sf
qk_sf <- st_sf(st_cast(st_sfc(qk_mp), "POINT"), quakes, crs=4326)
# run select demo for the quake data
# we will need the qk_sf
# to test
# plot(qk_sf)
library(mapedit)
library(mapview)
library(shiny)
ui <- fluidPage(
fluidRow(
# edit module ui
column(6, editModUI("editor")),
column(
6,
h3("Boxplot of Depth"),
plotOutput("selectstat")
)
)
)
server <- function(input, output, session) {
# edit module returns sf
edits <- callModule(editMod, "editor", mapview(qk_sf)@map)
output$selectstat <- renderPlot({
req(edits()$finished)
qk_intersect <- st_intersection(edits()$finished, qk_sf)
req(nrow(qk_intersect) > 0)
boxplot(
list(
all = as.numeric(qk_sf$depth),
selected = as.numeric(qk_intersect$depth)
),
xlab = "depth"
)
})
}
shinyApp(ui, server)
Error example:
Although I have posted this, along with others in the mapedit github issues page and r-spatial, I figured it would be worthwhile to see if there is a solution that doesn't require a package fix. I have found two workarounds for selectMod here and here, but the editMod source code is far more complex, so I've found it beyond my capacity to adapt this solution.
I've struggled to solve this issue for a few weeks on and off and would love to solve this and close this project.
Upvotes: 0
Views: 292
Reputation: 1
I found one easy bypass solution to deal with this issue. We have to clear the polygon or rectangle selector before we make the next selection. Also, if we don't clear the selection first, the previously selected data will be appended to the following selection.
Upvotes: 0
Reputation: 1
this is resolved on GitHub at https://github.com/r-spatial/mapedit/issues/106. remotes::install_github("r-spatial/mapedit")
solves the issue in the mapedit source code pending a package fix.
Upvotes: 0