0

I try to allow user to connect to google analytics account inside a shiny app (using 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)

this application works well in an interractive context, but not when deployed with shinyproxy I got this error :

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

how can i allow a user to log in to his google analytics account ?

My work is here : https://github.com/VincentGuyader/gauth

(Dockerfile, application.yml and source code)

Regards

Vincent Guyader
  • 2,927
  • 1
  • 26
  • 43
  • Do you have to allow an individual user to log in to their account, or can you use a Google "Service" account? – Steven Sep 04 '18 at 21:15

1 Answers1

0

The error indicates ga_auth() can not find an existing authentication cache file, and you are in a non-interactive session so can't create a new one.

Are you only connecting to your own Google Analytics account?

In that case the easiest way is to upload with your app the offline authentication token created when you use ga_auth() locally (called .httr-oauth or ga.oauth), then when you run ga_auth() in your Shiny application it will reuse your token.

You can indicate the token file specifically in the function e.g. ga_auth("ga.oauth") as well.

If you want a multi-user account where a user logins to their own account, you will need to use the specific Shiny functions as documented on the website.

MarkeD
  • 2,500
  • 2
  • 21
  • 35