Mounting a ShinyApp into a directory is causing problems whereas I am able to run that app within RStudio. I have a shiny app that reads Google Analytics data using library(googleAnalyticsR)
, library(googleAuthR)
.
The connection to Google Analytics is with a service account. I used a service acount because I understood it to be that by using aservice account I would not have to be concerned with authentication after downloading the service account json and pointing google gar_auth_service(service_account_credentials.json)
to it.
Everything works fine when I click to run the app within RStudio. Here's my script:
library(shiny)
library(tidyverse)
library(googleAnalyticsR)
library(googleAuthR)
library(DT)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
DT::dataTableOutput("example_sessions")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# authenticate with service ac■■■■ cedentials (uses googleAuth library)
gar_auth_service("/home/rstudio/credentials/service_account.json")
# try pulling ga sessions
view_id <- 123456 # my real id is different of course
# get data
## filter clauses
filter_funnel <- dim_filter(dimension = "shoppingStage",
operator = "REGEXP",
expressions = "^(ADD_TO_CART|CHECKOUT_[1-9]|PRODUCT_VIEW|TRANSACTION)$")
## events extract
ga_sessions <-
google_analytics(
view_id,
date_range = c("2020-04-01", "2020-04-02"),
metrics = c("users", "bounces", "transactions", "transactionRevenue"),
dimensions = c("yearMonth", "channelGrouping", "deviceCategory", "userType"),
anti_sample = TRUE,
samplingLevel = HIGHER_PRECISION,
max = -1
)
output$example_sessions <- DT::renderDataTable(DT::datatable({
ga_sessions %>% head
},
options = list(dom = 't', bPaginate = F, sScrollX="100%"),
rownames = F))
}
# Run the application
shinyApp(ui = ui, server = server)
Here's a screen shot of this running:
So, I am able to connect with Google Analytics using the service account json and create a shiny app with it.
The trouble comes from trying to host the app. I've hosted other apps without any issues in /srv/shiny-server/<app directory name>
.
I moved this single page app.R too /srv/shiny-server/MyTestApp
and then visited <my ip>:3838/
The app loads in that I can see it, but as soon as the UI is rendered I get a disconnected from server error.
I replaced the data frame resulting from the Google Analytics API call with just mtcars and that worked fine. This only happens when I try to reference Google Analytics.
How can I get my app to run with Google Analytics when it's in a hosted directory? Underlining that everything does run fine when I run the app from within RStudio, the issue only happens with hosting the app in a directory?