Search code examples
rshinydropboxshinyappsrdrop2

rdrop2 on shinyapps.io - authentication does not work


in order to be able to persistently store data created on Shinyapps.io, I have decided to use Dropbox via rdrop2. However, I have a problem: rdrop2 wants a manual authentication from Dropbox via the browser every time.

My plan was to intercept this via a dropkey.rds.

So I completed the authentication via the browser locally on my PC, saved the dropkey.rds and, to be on the safe side, put it in my www folder and in the directory where the corresponding script is located AND in the "project top folder". Simply so that the function can find the dropkey.rds for sure.

Unfortunately, it does not work. Even locally, the script asks me for authentication (at least the first time I run it). In Shinyapps, the programme simply crashes because no browser can open here.

How can I get around the authentication in Shinyapps.io?

You can find some code excerpts at the end of the post. Thank you!!!

Best regards


Code extract:

  token <- readRDS("droptoken.rds")
  drop_acc(dtoken = token)
  
  drop_upload(Pn, path = "test")

(Pn is just a Path to a png thatt should be uploaded)

Log Shinyapps.io

Waiting for authentication in browser... 2021-10-15T10:21:44.490437+00:00 shinyapps[48xxxxx]: Press Esc/Ctrl + C to abort 2021-10-15T10:21:44.491678+00:00 shinyapps[48xxxxx]: https://www.dropbox.com/oauth2/authorize?client_id=mxxxxxx2w&redirect_uri=xxxx 2021-10-15T10:21:44.491610+00:00 shinyapps[48xxxxxx]: Please point your browser to the following url:


Solution

  • Small update:

    I was able to solve the problem. The solution is as described here:

    To be extra clear for future readers, for a shiny app you should include your token as an RDS, and then either

    authenticate with that token like drop_auth(rdstoken = "tokenfile.rds") in global.R or at the top of server.R, then call other drop_() functions normally (without using the dtoken arg) do not call drop_auth(), read the token into R from the RDS file, then pass that token object into every drop_() function through the dtoken arg I think the first option is much, much better (and is what I do), but the second should still be viable.

    Putting the authentication at the top of the server.R (and for staftey the ui.R :D) solved the problem for me. Be aware, that you want to use the following rdrop2 commands at your script without calling the auth or the rds file again! :)