I'm currently working with an R Shiny App that utilizes googlesheets4 to read data in from a GoogleSheet. I recognize that authentication is important for accessing GoogleSheets, so I've tried authenticating the app using the code below in my app.R file (email and api key removed for privacy):
### AUTHENTICATE FOR GOOGLE SHEETS ACCESS ###
sheets_auth(
email = "MY EMAIL",
path = NULL,
scopes = "https://www.googleapis.com/auth/spreadsheets",
cache = gargle::gargle_oauth_cache(),
use_oob = gargle::gargle_oob_default(),
token = "MY API KEY"
)
When I run the dashboard locally with this code, it first loads a webpage asking that sign in to Google and authenticate Tidyverse's API: screenshot of Tidyverse API.... After I sign-in, the app opens in a separate window perfectly.
However, I don't want users to have to authenticate anything when using my dashboard once it's published. Ideally I would like the necessary information included in the Shiny code to allow for the app to authenticate access to the GoogleSheet on its own.
I am very new to googlesheets4, and APIs in general, so appreciate any and all guidance with getting the correct credentials into my app.R file.
Thank you!
UPDATE...4.23.20
After utilizing https://gargle.r-lib.org/articles/non-interactive-auth.html#provide-a-service-account-token-directly
I have been able to get this nearly worked out. The final hurdle is at the publishing phase, where I'm getting this error upon app launch:
Error: .auth not found Code as I have it now:
### AUTHENTICATE FOR GOOGLE SHEETS ACCESS ###
library(gargle)
library(googleAuthR)
library(searchConsoleR)
library(googledrive)
# Approach #1: use an option.
# Either specify the user:
options(gargle_oauth_email = "MY EMAIL")
# INSERT JSON FILE FROM GOOGLE API SERVICE ACCOUNT
drive_auth(path = "FTRjsonGoogleAPI.json")
options(gargle_quiet = FALSE)