【问题标题】:Use clickEvents in shiny with tmap在闪亮的 tmap 中使用 clickEvents
【发布时间】:2019-07-25 12:52:34
【问题描述】:

您可以将clickEvents 用于tmap 包,就像this example for leaflet in shiny 一样闪亮。

但是,我不知道如何访问点击事件。每次点击都会给出一个 ID,但这个 ID 链接到哪里?

请参阅下面的示例,其中单击事件打印在控制台上。

library(shiny)
library(tmap)
tmap_mode("view")
data("NLD_muni")

# User interface
ui <- fluidPage(
        mainPanel(
            leafletOutput("map")
        )
)

# Sever
server <- function(input, output) {

    # define map
    output$map <- renderLeaflet(
        tmap_leaflet(
            tm_shape(NLD_muni) +
                tm_polygons('pop_65plus') 
        )
    )


    # reactive values for map
    rv_map <-reactiveValues(Clicks=list())

    observeEvent(input$map_shape_click, {
        click <- input$map_shape_click
        print(str(click))
        rv_map$Clicks<-c(rv_map$Clicks, click$id)
        print(rv_map$Clicks)
    }) #END OBSERVE EVENT


}

# Run the application 
shinyApp(ui = ui, server = server)

【问题讨论】:

标签: r shiny observers r-leaflet tmap


【解决方案1】:

如果没有给定layerId,则id 链接到传单对象附加数据中的第一列。

所以解决方法是让第一列成为id列或在形状绘图函数中指定layerId

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 2021-02-08
    • 2021-08-30
    • 2020-10-31
    • 2019-10-22
    • 2021-06-14
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    相关资源
    最近更新 更多