Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run GoogleAnalyticsR in a Docker Container #418

Open
BaronBertil opened this issue Dec 20, 2022 · 0 comments
Open

Run GoogleAnalyticsR in a Docker Container #418

BaronBertil opened this issue Dec 20, 2022 · 0 comments
Assignees
Labels

Comments

@BaronBertil
Copy link

BaronBertil commented Dec 20, 2022

What goes wrong

Using this code from this website https://code.markedmondson.me/googleAnalyticsR/articles/shiny.html

and localy it's working fine but when I put it with in a Docker-Container I can log in but then I get the error message

Request Status Code: 403

I don't know whats going wrong here.

Steps to reproduce the problem

app.r

library(shiny)
library(googleAnalyticsR) # for accountPicker
library(googleAuthR)      # for gar_shiny_ui
options(shiny.port = 1221)
gar_set_client(scopes = c("https://www.googleapis.com/auth/analytics.readonly"), activate = "web")
options(googleAuthR.redirect = 'https://*********.a.run.app')
# options(googleAuthR.redirect = 'http://localhost:1221')
options(googleAuthR.verbose = 2)

## ui.R
ui <- fluidPage(
    title = "GA4 Shiny",
    h1("GA4 Shiny App"),
    accountPickerUI("auth_menu", inColumns = TRUE),
    h2("Pick metrics and dimensions"),
    metricDimensionSelectUI("mets1"),
    metricDimensionSelectUI("dims_custom", "Dimensions")
)

## server.R
server <- function(input, output, session){

    token <- gar_shiny_auth(session)

    ga_accounts <- reactive({
        req(token)
        ga_account_list("ga4")
    })

    property_id <- accountPicker("auth_menu",
                                 ga_table = ga_accounts,
                                 id_only = TRUE)

    meta <- reactive({
        req(property_id())

        ga_meta("data", propertyId = property_id())
    })

    metrics <- metricDimensionSelect("mets1", default = "sessions")
    dims_custom <- metricDimensionSelect("dims_custom",
                                         field_type = "dimension",
                                         custom_meta = meta())

}

shinyApp(gar_shiny_ui(ui), server)

.Renviron

GAR_CLIENT_WEB_JSON=./auth/client_secret_551343444456-trpgmtmso8kn17uj1dtg0itl32l6pjsc.apps.googleusercontent.com.json

Dockerfile

FROM rocker/tidyverse:latest

# Install R packages
RUN install2.r --error \
    shiny \
    remotes \
    DT
RUN R -e "remotes::install_github('MarkEdmondson1234/googleAuthR')"
RUN R -e "remotes::install_github('MarkEdmondson1234/googleAnalyticsR')"
# ENTRYPOINT Instruction
COPY . /RedCop
WORKDIR RedCop
run mkdir -p ~/.cache/gargle
ENTRYPOINT ["R", "-e", "shiny::runApp(port = 8080,host = '0.0.0.0')"] # Exec Form

Expected output

App is running

Actual output

Before you run your code, please run:

options(googleAuthR.verbose=2) and copy-paste the console output here.
Check it doesn't include any sensitive info like auth tokens or accountIds - you can usually just edit those out manually and replace with say XXX

'API Data failed to parse' diagnostics

If you have an error starting with:

API Data failed to parse.

  • Please install googleAuthR >v0.7.9000:
remotes::install_github("MarkEdmondson1234/googleAuthR")
  • Restart the R session and run your bugged code.
  • It should write a file called gar_parse_error.rds to your working directory.
  • Run the below to output some diagnostic information and paste the response here.
googleAuthR::gar_debug_parsing("gar_parse_error.rds")

Session Info

Please run sessionInfo() so we can check what versions of packages you have installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants