我想在用户单击 Leaflet 中的折线时触发单击事件,但我不确定发生这种情况的确切语法,而且我在任何地方都找不到它们的列表。我知道对于多边形来说是
<mapid>_shape_click
,对于标记来说是 <mapid>_marker_click
,但我尝试过 line/polyline/path_click 来触发它,但没有运气。
可重现的示例代码(如果需要):
library(shiny)
library(leaflet)
library(tidyverse)
ui <- fluidPage(
fluidRow(
column(
width = 12,
leafletOutput("map")
)
)
)
server <- function(input, output) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(lng = -100, lat = 37, zoom = 5) %>%
addPolylines(
lng = c(-100, -105),
lat = c(32, 42)
)
})
observeEvent(input$map_path_click, {
input$map_path_click %>% glimpse()
})
}
shinyApp(ui = ui, server = server)
你想使用形状
library(shiny)
library(leaflet)
library(tidyverse)
ui <- fluidPage(
fluidRow(
column(
width = 12,
leafletOutput("map")
)
)
)
server <- function(input, output) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(lng = -100, lat = 37, zoom = 5) %>%
addPolylines(
lng = c(-100, -105),
lat = c(32, 42)
)
})
observeEvent(input$map_shape_click, {
input$map_shape_click %>% glimpse()
})
}
shinyApp(ui = ui, server = server)