gpt4 book ai didi

r - 单击 map 后,ObserveEvent 不会打印出图层 ID

转载 作者:行者123 更新时间:2023-12-04 10:27:48 26 4
gpt4 key购买 nike

我试图通过点击 map 来获取国家信息,但国家名称或 Long/lat 没有打印出来。

任何人都可以在这个问题上启发我吗?

谢谢

该 map 来自自然地球。

library(rgdal)
library(shiny)
library(leaflet)

folder="."
country <- readOGR(dsn = folder, layer = "ne_110m_admin_0_countries", encoding="UTF-8")
country <- spTransform(country, CRS("+proj=longlat +ellps=GRS80"))

ui<-fluidPage(
leafletOutput('mymap')
)

server <- function(input, output, session){
# RV<-reactiveValues(Clicks=list())
output$mymap<- renderLeaflet(
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = country, layerId= ~ADMIN, fillColor = "red", fillOpacity = 1, color = "black",
stroke = T, weight = 1
)
)
observeEvent(input$map_shape_click, {
p<- input$map_shape_click
print(p$id) # click on map, no response
})
}

shinyApp(ui=ui, server=server)

最佳答案

您的 map 名称是“mymap”而不是“map”。所以你需要更换input$map_shape_clickinput$mymap_shape_click .

library(rgdal)
library(shiny)
library(leaflet)

folder="."
country <- readOGR(dsn = folder, layer = "ne_110m_admin_0_countries",
encoding="UTF-8")
country <- spTransform(country, CRS("+proj=longlat +ellps=GRS80"))

ui<-fluidPage(
leafletOutput('mymap')
)

server <- function(input, output, session){
# RV<-reactiveValues(Clicks=list())
output$mymap<- renderLeaflet(
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = country, layerId= ~admin, fillColor = "red",
fillOpacity = 1, color = "black",
stroke = T, weight = 1
)
)
observeEvent(input$mymap_shape_click, {
p<- input$mymap_shape_click
print(p$id) # click on map, no response
})
}

shinyApp(ui=ui, server=server)

关于r - 单击 map 后,ObserveEvent 不会打印出图层 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49881202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com