【问题标题】:Read .csv file from dropbox and plot it on leaflet map in shiny app从保管箱中读取 .csv 文件并将其绘制在闪亮应用程序的传单地图上
【发布时间】:2016-06-26 05:00:15
【问题描述】:

我想在地图上绘制 4 个站点。可以下载the data from here.

使用下面的代码,我设法绘制了它们

library(shiny)
library(leaflet)
stations <- read.csv("~path/stations.csv")
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("map", width = "100%", height = "100%")) 
server <- function(input, output) {
output$map <- renderLeaflet({
leaflet(stations) %>%
  addProviderTiles("Esri.WorldTopoMap") %>%
  addCircleMarkers(~x,~y)
})
}
shinyApp(ui, server)

这是结果

现在,在最终的shiny 应用程序中,我想从保管箱中读取.csv 文件。

按照method described in this link,我尝试了以下

library(repmis)
myfilename <- "stations.csv"
mykey <- "i9pw95ltjown2uc"
stations <- source_DropboxData(myfilename, key=mykey, sep=",", header=TRUE)

我收到了这个错误

source_DropboxData(myfilename, key = mykey, sep = ",", header = TRUE) 中的错误: 未使用的参数 (myfilename, key = mykey, sep = ",", header = TRUE)

使用the answer in this link,我试过了

stations <- read.csv(url("https://www.dropbox.com/s/i9pw95ltjown2uc/stations.csv?dl=0"))

我收到了这个错误

read.table 中的错误(file = file,header = header,sep = sep,quote = quote,:不允许重复的 'row.names'

我试过answer of this question

stations <- read.csv("https://www.dropbox.com/s/i9pw95ltjown2uc/stations.csv?dl=0",
 row.names=NULL)

str(stations) 显示它有 1465 个观察值。

#'data.frame':  1465 obs. of  2 variables:

任何关于如何从保管箱中读取.csv 以便能够将其绘制在传单地图上的建议将不胜感激。

【问题讨论】:

    标签: r csv shiny leaflet dropbox


    【解决方案1】:

    使用?raw=1 而不是?dl

    stations <- read.csv(url("https://www.dropbox.com/s/i9pw95ltjown2uc/stations.csv?raw=1"))
    
    > head(stations)
      stations         x       y
    1 station1  -77.2803 35.8827
    2 station2  -79.1243 42.4356
    3 station3  -93.4991 30.0865
    4 station4 -117.6321 34.0905
    

    参考from dropbox website

    【讨论】:

    • 优秀的答案!谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 2018-09-30
    • 2020-05-11
    相关资源
    最近更新 更多