Reputation: 155
Is there any way to run the shiny app directly from dropbox? I have tried the package 'rdrop2' without success. The link to the package is here:
However, when I follow the instructions in that link and use command:
drop_download('path/to/file/data.csv', dtoken = token.rds)
I get the following error message:
Error: Path exists and overwrite is FALSE
Does anyone know how to work around this error? Additionally, most of the data on dropbox is maintained in excel files. Is there any straight forward way to read an excel file from dropbox directly into R?
Thanks
Upvotes: 0
Views: 1016
Reputation: 4072
First of all I think you need to pass the token itself rather than the .rds
file:
token <- readRDS("token.rds")
As the error message states data.csv
most likely exists in your working directory. You can check it with file.exists("data.csv")
. If it returns TRUE
your file already exists, so you have 3 options:
if
statementCheck with an if statement whether a file exists and only download if it doesn't exist:
if( !file.exists("data.csv")) {
drop_download("data.csv", dtoken = token)
}
overwrite = T
If you think it's an updated version of the file you can set the overwrite
argument to TRUE
drop_download("data.csv", dtoken = token, overwrite = T)
Only download if the dropbox version is newer:
Like this:
if( !file.exists("data.csv")) {
drop_download("data.csv", dtoken = token)
} else {
if (file.info("data.csv")$mtime < drop_get_metadata("data.csv")$client_modified) {
drop_download("data.csv", dtoken = token)
}
}
Please keep in mind though that the timezone can be different on the dropbox metadata causing unexpected results.
If you want to read in a file from dropbox
use drop_read_csv
.
Here's a minimal shiny app that should work if you:
"token.rds"
using drop_auth()
and saveRDS
"data.csv"
uploaded to your root folder on dropbox.Code:
library(shiny)
token <- readRDS("token.rds")
new_data <- drop_read_csv("data.csv")
ui <- fluidPage(
tableOutput("table")
)
server <- function(input, output, session) {
output$table <- renderTable( {
new_data
})
}
shinyApp(ui, server)
Upvotes: 2