-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
I put together some code to display data points on a map and then added in the edit functionality. My question is: Is it be possible to then take the selected data and push it to a data frame on Shiny that say, could be downloaded by the end user in CSV? Below is a screenshot of what it looks like so far, so the idea would be to take all the data points selected and push it to a CSV within Shiny:
library(mapedit)
library(mapview)
library(shiny)
library(leaflet)
library(leaflet.extras)
library(sf)
# select as a module
m = leaflet(turf_clean_mapped) %>%
addCircleMarkers(weight = 1, layerId = 1:nrow(turf_clean))
ui <- tagList(
selectModUI("test-mod"),
DT::dataTableOutput("selected")
)
server <- function(input, output, session) {
selections <- callModule(selectMod, "test-mod", m)
output$selected <- DT::renderDataTable({DT::datatable(selections())})
observe({str(selections())})
}
shinyApp(ui, server)
# edit as a module
m = mapview(turf_clean_mapped)@map
testsf = NULL
ui <- tagList(
editModUI("test-edit"),
h1("What You Draw"),
leafletOutput("edited")
)
server <- function(input, output, session) {
crud <- callModule(editMod, "test-edit", m, "turf_clean_mapped")
output$edited <- renderLeaflet({
req(crud()$finished)
mapview(crud()$finished)@map
})
}
shinyApp(ui, server)
# editMap module can easily be combined to make a selection tool
# do selection of breweries with drawn polygons
ui <- fluidPage(
fluidRow(
column(6,editModUI("brew-select")),
column(6,leafletOutput("mapout"))
)
)
server <- function(input,output,session) {
m = mapview(turf_clean_mapped)@map
turf_sf <- st_as_sf(turf_clean_mapped)
drawn <- callModule(editMod, "brew-select", m)
calc_sf <- reactiveValues()
observe({
req(drawn()$finished)
calc_sf$intersection <- st_intersection(drawn()$finished, turf_sf)
})
output$mapout <- renderLeaflet({
req(calc_sf$intersection)
(mapview(calc_sf$intersection) + mapview(drawn()$finished))@map
})
}
shinyApp(ui,server)
Metadata
Metadata
Assignees
Labels
No labels