我尝试允许用户在闪亮的应用内连接谷歌分析帐户(使用shinyproxy):
library(shiny)
library("googleAnalyticsR")
options(googleAuthR.verbose=2)
ui <- fluidPage(
actionButton(inputId = "go",label = "go"),
verbatimTextOutput("log")
)
server <- function(input, output, session) {
info <- reactiveValues()
observeEvent(input$go,{
message("clic")
ga_auth(new_user = TRUE)
info$account_list <- ga_account_list()
})
output$log <- renderPrint({
print(info$account_list)
})
}
shinyApp(ui, server)
这个应用程序在交互式上下文中运行良好,但是当使用shinyproxy部署时我没有收到此错误:
2018-08-31 21:01:34> No local token found in session
2018-08-31 21:01:34> Auto-refresh of token not possible, manual re-authentication required
Warning: Error in : Authentication options didn’t match existing session token and not interactive session
so unable to manually reauthenticate
78: stop
77: make_new_token
76: gar_auth
75: gar_auto_auth
74: ga_auth
73: observeEventHandler [/usr/local/lib/R/site-library/gauth/app/app.R#27]
2: shiny::runApp
1: gauth::run_app
我如何允许用户登录他的Google分析帐户?
我的工作在这里:https://github.com/VincentGuyader/gauth
(Dockerfile,application.yml和源代码)
问候
该错误表明ga_auth()
无法找到现有的身份验证缓存文件,并且您处于非交互式会话中,因此无法创建新的身份验证缓存文件。
您是否只是连接到自己的Google Analytics帐户?
在这种情况下,最简单的方法是使用您的应用程序上传当您在本地使用ga_auth()
时创建的脱机身份验证令牌(称为.httr-oauth
或ga.oauth
),然后当您在Shiny应用程序中运行ga_auth()
时,它将重用您的令牌。
您可以在功能中明确指出令牌文件,例如ga_auth("ga.oauth")
也是如此。
如果您想要一个用户登录自己帐户的多用户帐户,则需要将特定的Shiny功能用作documented on the website。