Read .csv file from dropbox and plot it on leaflet map in shiny app

I have 4 stations that I want to plot on map. You can download the data from here.

Using the code below, I managed to plot them

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)

and here is the result

Now, in the final shiny app, I want to read the .csv file from dropbox.

Following the method described in this link, I tried the following

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

I got this error

Error in source_DropboxData(myfilename, key = mykey, sep = ",", header = TRUE) : unused arguments (myfilename, key = mykey, sep = ",", header = TRUE)

Using the answer in this link, I tried

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

I got this error

Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

I tried the answer of this question

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

but str(stations) showed it has 1465 observation.

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

Any suggestions how to read .csv from dropbox to be able to plot it on leaflet map would be appreciated.

Answers


Use ?raw=1 rather than ?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

Reference from dropbox website


Need Your Help

Sort multidimensional array and keep index C++

c++ arrays sorting

Is it possible to sort a multidimensional array (row by row) using sort in C++ such that I can keep the index?