Is there a way to auto-authenticate access to GoogleSheets upon R Shiny App load? Googlesheets4 authentication trouble

瘦欲@ 提交于 2020-12-13 19:05:44

问题


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)

来源:https://stackoverflow.com/questions/61375368/is-there-a-way-to-auto-authenticate-access-to-googlesheets-upon-r-shiny-app-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!