使用googlesheets4在R中通过Shiny连接到googlesheets4 [英] Connect to googlesheets via shiny in R with googlesheets4
问题描述
I'm trying to use an updated version of this example to connect to a private googlesheet via shiny, and deploy this app on the shinyapps.io server. The user is not required to authenticate to a google account as the app uses a specified pre-existing googlesheet.
I've followed this example (partly copied here), attempting to save the token to my shiny app:
# previous googlesheets package version:
shiny_token <- gs_auth() # authenticate w/ your desired Google identity here
saveRDS(shiny_token, "shiny_app_token.rds")
,但尝试将其更新为googlesheets4,如下所示:
but tried to update it to googlesheets4, like this:
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()
函数之外.
Then in the app, I have placed this code outside the shinyApp()
function.
load("data/tk.rdata")
googlesheets4::gs4_auth(token = ss_token, use_oob = T)
在应用程序中,我使用从那里获得的硬编码ID连接到该应用程序的google doc
ss$spreadsheet_id
以上.该应用程序可在本地运行.
In the app, I connect to a google doc from the app, using a hardcoded id obtained from
ss$spreadsheet_id
above. The app works locally.
尝试将应用程序部署到服务器后,出现错误"...无法获取Google凭据.您是否在非交互式会话中运行googlesheets4?...等等";我认为令牌将为此包含足够的信息.
After attempting to deploy the app to the server I get the error "...Can't get google credentials. Are you running googlesheets4 in a non-interactive session?... etc" I thought that the token would contain sufficient information for this.
如果有人可以向我指出进行此设置的指南,并对此方法(将令牌保存在Shinyapps.io上)是否安全,我将不胜感激.
I'd be grateful if anyone can point me to a guide to setting this up, and also comment on whether this approach (saving a token on the shinyapps.io) is safe?
我看过其他示例,但似乎大多数用于googlesheets
的先前版本
I've looked at other examples, but it seems most are for the previous version of googlesheets
推荐答案
只需按照 查看全文