2015-11-10 100 views
1

AIM如何使用閃亮

創建使用閃亮,表示一組用圓圈標記數據的單張地圖,並添加一個標記爲使用第二組數據點的多個對象添加到單張地圖。

ISSUE 「圓」標記正在工作,但「標記」不是。 「addMarkers」代碼沒有被讀取或被忽略。

SERVER

library(shiny) 
    library(leaflet) 

    server <- function(input, output, session) { 

    points <- read.csv(textConnection("Loc,STZip,Lat,Long,Vol 
           Loc1,17699,40.0185,-76.297582,15 
           Loc2,76177,32.949819,-97.31406,20 
           Loc3,27801,35.935125,-77.77076,17 
           Loc4,52404,41.947335,-91.68819,12 
           Loc5,19380,39.983108,-75.59332,18 
           ")) 
    newpoints <- read.csv(textConnection("Loc,STZip,Lat,Long,Vol 
           Loc6,18640,41.317242,-75.77942,12 
            Loc7,38133,35.208709,-89.80518,20 
           ")) 

    output$mymap <- renderLeaflet({ 
    leaflet() %>% 
    addProviderTiles("Stamen.TonerLite", 
        options = providerTileOptions(noWrap = TRUE)) %>% 
    addCircleMarkers(lng = ~Long, lat = ~Lat, radius = ~Vol, layerId = NULL, 
      group = "NGS_Facilities", stroke = TRUE, color = "#0000CC", weight = 5, opacity = 0.5, 
      fill = TRUE, fillColor = "#0000CC", fillOpacity = 0.2, dashArray = NULL, 
      popup = ~Loc, options = pathOptions(), clusterOptions = NULL, clusterId = NULL, 
      data = (newpoints)) %>% 

    #this code is not being read or is ignored... 
    addMarkers(lng = ~Long, lat = ~Lat, popup = ~Loc, data = (newpoints)) 


}) 

}

UI

庫(有光澤) 庫(單張)

r_colors <- rgb(t(col2rgb(colors())/255)) 
names(r_colors) <- colors() 

ui <- fluidPage(
    title = "Map of Stuff", 
    leafletOutput("mymap", width = 1800, height = 800), 
    p() 
) 
+0

我早些時候曾在代碼中的錯誤。我按照你的建議將%>%移動到前一行的末尾,並將「addmarker」代碼改爲:addMarkers(lng =〜Long,lat =〜Lat,data =(newpoints))我沒有收到錯誤,但我也沒有得到標記。 –

回答

2

這是一個衛RD錯誤...與它戰鬥了一段時間,直到我意識到它是如何讀取數據的問題。

> newpoints 
             Loc STZip  Lat  Long Vol 
1         Loc6 18640 41.31724 -75.77942 12 
2         Loc7 38133 35.20871 -89.80518 20 
3           NA  NA  NA NA 

因爲你的結束報價是在一個新的行,它會留下一個休息。這會導致數據中的最後一行爲NA s。當我調試時,它看起來像我在數據顯示之前放置的任何東西,但之後會失敗。

爲了解決這個問題,看了你的數據:

points <- read.csv(textConnection("Loc,STZip,Lat,Long,Vol 
           Loc1,17699,40.0185,-76.297582,15 
           Loc2,76177,32.949819,-97.31406,20 
           Loc3,27801,35.935125,-77.77076,17 
           Loc4,52404,41.947335,-91.68819,12 
           Loc5,19380,39.983108,-75.59332,18")) 
    newpoints <- read.csv(textConnection("Loc,STZip,Lat,Long,Vol 
           Loc6,18640,40.0185,-76.297582,12 
            Loc7,38133,35.208709,-89.80518,20")) 

無論出於何種原因,單張蟲子,如果最後一行是所有NA小號

+0

感謝您的幫助!我無處可去,但它現在適合我! –