如何用传单阅读闪亮的标记数据

时间:2014-09-29 16:49:05

标签: r leaflet shiny

我在闪亮的应用程序中播放传单,我想获得有关我点击的标记的信息。此时我有一个带标记的漂亮地图,但是如何返回有关我点击的标记的信息?

我的服务器.R

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



setwd("~/github/shiny_stuff/banyuls_map/")
####load data converted in geojson
capteurs<-readOGR("./data/capteurs.geojson", "OGRGeoJSON")

shinyServer(function(input, output, session) {
  map <- createLeafletMap(session, "map")
  session$onFlushed(once=TRUE, function() {
    map$addMarker(capteurs@coords[,2], 
               capteurs@coords[,1]
                  )
  })

})

我的ui.R

library(shiny)
library(leaflet)



shinyUI(fluidPage(
  titlePanel("title panel"),

  leafletMap(
    "map", "100%", 400,
    initialTileLayer = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
    initialTileLayerAttribution = HTML('Maps by <a href="http://www.mapbox.com/">Mapbox</a>'),
    options=list(
      center = c(42.4797, 3.1181),
      zoom = 12
    )
  ),



))

enter image description here

2 个答案:

答案 0 :(得分:4)

我相信你想看看:

input$map_marker_click

示例bquast引用使用input$map_shape_click 但这是基于您已加载的leafletMap中包含的基础GeoJSON数据。

您可以使用map_marker_click返回的信息来查询您的数据并将其插入弹出窗口。

答案 1 :(得分:2)

最简单的方法是查看传单地图示例中的内容,例如此处的示例:

http://glimmer.rstudio.com/jcheng/leaflet-demo/

您可以在此处找到此示例的代码:

https://github.com/jcheng5/leaflet-shiny/blob/master/inst/examples/population/server.R

该对象名为map$showPopup,可在第118行找到。