shashwat vajpeyi
shashwat vajpeyi

Reputation: 155

rdrop 2, excel and shiny markdown

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:

rdrop2 at github

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

Answers (1)

GyD
GyD

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:

  1. Use an if statement

Check 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)
}
  1. Set 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)
  1. Only download if the dropbox version is newer:

    • If the file doesn't exist, download the file
    • If not, check whether the dropbox version has been updated.

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.

Edit:

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:

  • Created "token.rds" using drop_auth() and saveRDS
  • Have a file called "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

Related Questions