点击标记打开绘图/数据表 [英] Click on marker to open plot / data table
问题描述
我正在制作闪亮的传单.这些工具是基本的,我有一张带有一些标记的地图(来自带有 LONG 和 LAT 的表格).
I'm working on leaflet with shiny. The tools is basic, i have a map with some markers (coming from a table with LONG and LAT).
我想要做的是当我点击标记时打开一个表格或图表.
What I want to do is to open a table or a graph when i click on the marker.
有简单的方法吗?
你有一个非常简单的例子吗:你在地图上有一个制造者,你点击标记,然后有一个图或一个表格或 jpeg 正在打开?
Do you have a really simple example: you have a maker on a map, you click on the marker, and there is a plot or a table or jpeg that s opening?
推荐答案
这是另一个例子,取自这里和有点适应.当你点击一个标记时,下表会相应改变.
Here is another example, taken from here and a little bit adapted. When you click on a marker, the table below will change accordingly.
除此之外,这里的手册是一个很好的资源:https://rstudio.github.io/leaflet/shiny.html
Apart from that, a good resource is this manual here: https://rstudio.github.io/leaflet/shiny.html
library(leaflet)
library(shiny)
myData <- data.frame(
lat = c(54.406486, 53.406486),
lng = c(-2.925284, -1.925284),
id = c(1,2)
)
ui <- fluidPage(
leafletOutput("map"),
p(),
tableOutput("myTable")
)
server <- shinyServer(function(input, output) {
data <- reactiveValues(clickedMarker=NULL)
# produce the basic leaflet map with single marker
output$map <- renderLeaflet(
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addCircleMarkers(lat = myData$lat, lng = myData$lng, layerId = myData$id)
)
# observe the marker click info and print to console when it is changed.
observeEvent(input$map_marker_click,{
print("observed map_marker_click")
data$clickedMarker <- input$map_marker_click
print(data$clickedMarker)
output$myTable <- renderTable({
return(
subset(myData,id == data$clickedMarker$id)
)
})
})
})
shinyApp(ui, server)
这篇关于点击标记打开绘图/数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!