-
Notifications
You must be signed in to change notification settings - Fork 33
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
Can you plot reactive data using editMod? #76
Comments
@m-e-cws I will try to demonstrate a way of achieving your objective soon. Thanks for the report. |
Just to bring this comment back up to top of mind- I can get reactivity to work after loading in the basemap with a leaflet proxy. I was using isolate to break the reactivity before loading in the basemap, but I can’t get the basemap to change and display the reactive data I need. Any thoughts on how to accomplish this? |
@davis3tnpolitics: I'm running into the same problem. Here's an example taken from mapedit demo. The code line of interest is I've tried several suggestion from forums but no luck:
The only way to get it to work is with library(mapedit)
library(mapview)
library(shiny)
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)
ui <- fluidPage(
fluidRow(
# edit module ui
column(6, editModUI("editor")),
column(
6,
h3("Boxplot of Depth"),
plotOutput("selectstat")
)
)
)
server <- function(input, output, session) {
qk_rv <- reactive({qk_sf})
# edit module returns sf
edits <- callModule(editMod, "editor", mapview(qk_rv())@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) |
Hi @davis3tnpolitics @leungi , Thank you both for bringing this issue back to my attention. I had originally posted this almost two years ago, and since then I have learned a lot about reactive datasets and how they interact with leaflet maps and shiny apps. I have managed to solve my own problem, and I should have posted my own solution sooner. Below is the code which allows to subset data in an interactive leaflet map by both a slider bar, and by drawing a shape over points. Feel free to check out a map I made which includes some extra tools for subsetting and selecting data in a leaflet map: https://englishm.shinyapps.io/Plastics/
|
Thanks prompt response and sharing @m-e-cws! The commenting really helps with my understanding 🙏 |
@m-e-cws: have you encountered a case for your solution above where the CRS of the initial map (i.e. For such a case, even after setting the I posted this issue with |
Just to be clear, setting a crs won't change the coordinates. You need to |
Thanks for tip @tim-salabim! This is one of those rare moments where I have to deal with objects with I tried your suggestion, but got the following error, which is logical given # edits() is objected returned from mapedit selection
selected <- edits()$finished
selected_trf <- selected %>% st_transform(crs = NA_crs_)
#> Error in st_transform.sfc: sfc object should have crs set |
Hello,
I am self-taught in R and computer coding, so I apologize if this question is poorly worded or already answered elsewhere.
I am trying to plot a reactive dataset in editMod, while retaining the ability to use the edit (draw) functions provided by editMod. So far I have not found a way to plot reactive data using editMod.
I want a map that allows me to:
Plot spatial data that can be subsetted by some kind of reactive variable (below it is the "mag" variable)
Draw across a certain group of points and generate summary data based on the reactive subset of the plotted data.
Below is a reproducible example using the supplementary "quakes" dataset. In the below map, I can generate summary data based on a reactive dataset selected by the slider bar, but the reactive dataset is not reflected in what is plotted on the map.
The text was updated successfully, but these errors were encountered: