使用Leaflet

时间:2016-06-06 10:45:32

标签: javascript r shiny rmaps

我正在尝试与@Ramnath类似https://github.com/ramnathv/bikeshare,但我无法将标记/点显示在地图上。

以下是代码:

shinyServer(function(input, output, session) { 
  output$interactivemap  <- renderMap({
  map <- Leaflet$new()
  map$setView(c(lng = 2.812500, lat = 46.732331), zoom = 6)
  map$tileLayer(provider = "Stamen.TonerLite")
  map$fullScreen(TRUE)
  map$geoJson(toGeoJSON(data = data_set(), lat.lon = c(1,2)))
    onEachFeature = "#! function(feature, layer){
        layer.bindPopup(feature.properties.popup)
        } !#",
    pointToLayer =  "#! function(feature, latlng){
        return L.circleMarker(latlng, {
            radius: 40,
            fillColor: '#ff7800',
            color: '#000',
            weight: 1,
            fillOpacity: 0.8
        })
    } !#")
  map$set(width = 1600, height = 800)
  map
})

shinyUI(navbarPage("Campaign Reporting", id="nav",
   tabPanel("Interactive Map",
    div(class="outer",
        tags$head(
            includeCSS("styles.css"),
            includeScript("gomap.js")
        ),
        mapOutput('interactivemap'),
        ),
   tabPanel("blabla")
))

其中data_set()(在server.R中)是一个数据帧(在renderMap上面生成但我没有在这里写),例如:

Picture of data_set()

任何帮助将不胜感激!谢谢:))

修改:数据:structure(list(lat = c(48.86, 48.7207222, 50.4324341, 49.1191, 47.865, 43.4546, 45.75, 49.4193, 46.1417, 45.8347, 44.8333, 49.2392, 47.3167, 43.6, 43.6603, 43.7031, 47.4173, 48.3773, 45.1667, -21 ), lon = c(2.35, 7.89293766, 2.99834633, 6.1727, 0.4815, 5.4699, 4.85, 0.5776, -0.2218, 1.3276, -0.5667, -1.0105, 5.0167, 3.8833, -1.308, 7.2661, -1.8468, -4.3061, 5.7167, 55.2667), value = c(0.10004, 0.12544, 0.12404, 0.14432, 0.12699, 0.12511, 0.13578, 0.10963, 0.14525, 0.13005, 0.14318, 0.11648, 0.11883, 0.12853, 0.09893, 0.11225, 0.11459, 0.11165, 0.12204, 0.17852), nbImp = c(135199L, 3698L, 8078L, 3022L, 2682L, 5709L, 7040L, 2678L, 1735L, 4306L, 3242L, 1649L, 2865L, 4003L, 1390L, 2710L, 4601L, 1459L, 3703L, 231L)), .Names = c("lat", "lon", "value", "nbImp"), row.names = c("197114", "100913", "68284", "51182", "176719", "181879", "74930", "180304", "7126", "26166", "186426", "160141", "116541", "170444", "96232", "184107", "52826", "16672", "84754", "78867"), class = "data.frame")

0 个答案:

没有答案