這是一個後續的貼here網絡的R閃亮/ R +工作室與rMaps KML
使用jdharrison開發的代碼和討論here的問題,這裏是一個最小的ui.R:
library(shiny);library(rCharts)
shinyUI(fluidPage(
mainPanel(
tabPanel("Interactive", tags$style('.leaflet {height: 1000px;}'),
showOutput('mapPlot', 'leaflet'))
)) )
和最小server.R:
library(shiny);library(rCharts);library(rMaps)
shinyServer(function(input, output,session) {
output$mapPlot <- renderMap({
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addAssets(css = NULL, jshead = 'http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js')
map1$addKML('leaflet/placemark.kml')
leafletLib <- file.path(find.package("rMaps"), "libraries", "leaflet")
sampleKml <- readLines('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
write(sampleKml, file.path(leafletLib, 'placemark.kml'))
map1
}) })
當我RStudio
或我的服務器上運行shiny::runApp()
在現場網站上,我收到一張空白地圖,類似於我在上述解決方案之前在本地出現的問題。
我確定這與KML文件的位置以及可能的文件權限有關,但我在使用KML文件時遇到了一些困難。
感謝您提供任何提示或資源。
更新:我在本地嘗試並獲得相同的結果。所以,我不確定它與我的服務器網絡有什麼關係......
甜!我將不得不放棄所有這些,並使用togeojson與geoJSON一起使用,但是我已經有了使用KML工作的顏色和標籤,非常感謝。 – ideamotor
樂於助人。這是一個臨時解決方案Ramnath正在研究rCharts/rMaps的下一次迭代,因此上述內容將不再必要。 – jdharrison
酷,當然也支持他! – ideamotor