我想创建一个传单地图,您可以在其中选择多个多边形,这将selectizeInput()在一个闪亮的应用程序中更新。这将包括删除选定的多边形(当它在selectizeInput().
我稍微更改/更新了此处答案中的代码(使用 sf 而不是 sp 和更多 dplyr,我可以在其中计算出基本 R 是什么)。
多边形可能可以通过observeEvent绑定来更新input$clicked_locations,但不确定具体如何。
这是代码:
library(shiny)
library(leaflet)
library(sf)
library(dplyr)
#load shapefile
nc <- st_read(system.file("shape/nc.shp", package="sf")) %>%
st_transform(4326)
shinyApp(
ui = fluidPage(
"Update selectize input by clicking on the map",
leafletOutput("map"),
"I would like the selectize input to update to show all the locations clicked,",
"but also when items are removed here, they are removed on the map too, so linked to the map.",
selectizeInput(inputId …Run Code Online (Sandbox Code Playgroud) 我想做的很简单.我希望能够在Shiny/Leaflet地图上保存所有点击事件.这是一些示例代码:
library(raster)
library(shiny)
library(leaflet)
#load shapefile
rwa <- getData("GADM", country = "RWA", level = 1)
shinyApp(
ui = fluidPage(
leafletOutput("map")
),
server <- function(input, output, session){
#initial map output
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = rwa,
fillColor = "white",
fillOpacity = 1,
color = "black",
stroke = T,
weight = 1,
layerId = rwa@data$OBJECTID,
group = "regions")
}) #END RENDER LEAFLET
observeEvent(input$map_shape_click, {
#create object for clicked polygon
click <- input$map_shape_click
print(click$id)
}) #END OBSERVE EVENT
}) …Run Code Online (Sandbox Code Playgroud)