我正在尝试使用此example的更新版本通过shiny连接到一个私有googlesheet,并在shinyapps.io服务器上部署此应用程序。用户不需要向google帐户进行身份验证,因为应用程序使用指定的预先存在的googlesheet。
我关注了这个example (这里复制了一部分),试图将这个令牌保存到我闪亮的应用程序中:
# previous googlesheets package version:
shiny_token <- gs_auth() # authenticate w/ your desired Google identity here
saveRDS(shiny_token, "shiny_app_token.rds")但尝试将其更新为googlesheets4,如下所示:
ss <- gs4_get("MY GOOGLE DOC URL") # do the authentication once, manually.
ss
gs4_has_token() # check that the token exists
# get token
ss_token <- gs4_token()
# save the token
save(ss_token, file = "APP PATH ... /data/tk.rdata")然后在应用程序中,我将此代码放在shinyApp()函数之外。
load("data/tk.rdata")
googlesheets4::gs4_auth(token = ss_token, use_oob = T)在该应用程序中,我使用从上面的ss$spreadsheet_id获得的硬编码id,从该应用程序连接到谷歌文档。该应用程序在本地运行。
在尝试将应用程序部署到服务器后,我收到错误消息“...无法获取谷歌凭据。您是否在非交互会话中运行googlesheets4?...等”我认为令牌应该包含了足够的信息。
如果有人能给我一个设置指南,并评论一下这种方法(在shinyapps.io上保存令牌)是否安全,我将不胜感激。
我看过其他示例,但似乎大多数都是针对以前版本的googlesheets的
发布于 2020-09-16 18:05:20
只需按照this链接中的说明进行操作:
# designate project-specific cache
options(gargle_oauth_cache = ".secrets")
# check the value of the option, if you like
gargle::gargle_oauth_cache()
# trigger auth on purpose to store a token in the specified cache
# a broswer will be opened
googlesheets4::sheets_auth()
# see your token file in the cache, if you like
list.files(".secrets/")
# sheets reauth with specified token and email address
sheets_auth(
cache = ".secrets",
email = "youremail"
)https://stackoverflow.com/questions/63535190
复制相似问题