R/app_global.R

Defines functions app_global

#' Global variables to use in Server and UI functions are saved to 'inst/extdata/global.rds' file.
#'
#' @importFrom httr oauth_endpoints oauth_app
#' 
#' @noRd
app_global <- function() {
  
  # # Authentication setup
  # drive_user <- get_golem_options("drive_user") # User with permissions to Tidyverse Apps third party applications
  # drive_path <- get_golem_options("drive_path") # Drive path to client folder
  # drive_api_key <- get_golem_options("drive_api_key")
  
  if (get_golem_options("drive_update")) {
    download_client_data(
      # User with permissions to Tidyverse Apps third party applications
      drive_user = get_golem_options("drive_user"), 
      # Drive path to client folder
      drive_path = get_golem_options("drive_path"), 
      drive_api_key = get_golem_options("drive_api_key"),
      output_dir = "inst/app"
    )
  }
  
  print(getwd())
  
  case_conf <- config::get(file = "inst/app/case-config.yml")
  
  print(case_conf)
  
  auth_conf <- list(app_name = "Google authentication",
                    client_id = case_conf$google_auth$client_id,
                    client_secret = case_conf$google_auth$client_secret,
                    resource_uri = case_conf$google_auth$resource_uri,
                    redirect_uri = case_conf$google_auth$redirect_uri,
                    endpoint = httr::oauth_endpoints("google"),
                    scope = "https://www.googleapis.com/auth/userinfo.email",
                    users = case_conf$google_auth$users)
  
  if (interactive()) {
    options(shiny.port = 5295)
    auth_conf$resource_uri <- "http://localhost/"
    auth_conf$redirect_uri <- "http://localhost:5295"
  }
  
  auth_app <- httr::oauth_app(
    appname = auth_conf$app_name,
    key = auth_conf$client_id,
    secret = auth_conf$client_secret
  )
  
  glob <- list(
    server_conf = case_conf$server,
    ui_conf = case_conf$ui,
    auth = list(
      conf = auth_conf,
      app = auth_app
    )
  )
  
  # Save global variables
  
  saveRDS(glob, file = 'inst/app/global.rds')
  
  
}
mcanigueral/testapp documentation built on June 30, 2020, 2:55 p.m.