Search code examples
rshinyshinyappsgmailr

Running gmailr in shinyapps.io


I just deployed a shiny app in shinyapps.io.

It worked fine locally but when I deployed it, the gmailr authentication popup did not appear.

I checked the logs in shinyapps.io, and it is working in the background but not in the front end.

For example, when I run the function:

options(httr_oauth_cache=T)
gmailr::clear_token()
gmailr::gmail_auth()

The logs in shinyapps.io shows this which is expected, but no popup:

enter image description here

The expected output should be a popup asking me to choose which gmail account to authenticate.

Anyone have any experience using the gmailr package in shiny?

EDIT:

There is a file called .httr-oauth in my directory, but not rsconnect.

enter image description here

Should I copy this file to my rsconnect folder?

This is the directory to my app in shinyapps.io through rconnect:

enter image description here


Solution

  • Figure it out if anyone wants to reference this in the future:

    Steps to host Gmailr in Shiny Apps:

    1) set your options locally to be:

    options(httr_oob_default = TRUE, httr_oauth_cache=TRUE)

    gmailr::clear_token()

    Run your Shiny App.

    2) A popup will appear for you to select your gmail account.

    3) Instead of automatically connecting you, an authentication code will appear. You need to copy and paste that authentication code in your r console where it prompts you to paste it.

    4) In your work directory, you will now have a httr oauth file saved. That is what grants you access to your gmail account.

    5) Exit the shiny app. Remove the options from the script and save:

    options(httr_oob_default = TRUE, httr_oauth_cache=TRUE)

    gmailr::clear_token()

    6) Upload the shiny app with the httr oauth file in your directoy to shinyapps.io

    App should call your gmail account now without asking you to authenticate!