ga_model_shiny: Create a Shiny app from a ga_model file

Description Usage Arguments Details Template macro variables See Also Examples

View source: R/model_shiny_templates.R

Description

Create a Shiny app from a ga_model file

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
ga_model_shiny(
  models,
  template = ga_model_shiny_template("basic"),
  header_boilerplate = TRUE,
  title = "ga_model_shiny",
  auth_dropdown = c("ga4", "universal", "none"),
  web_json = Sys.getenv("GAR_CLIENT_WEB_JSON"),
  date_range = TRUE,
  scopes = "https://www.googleapis.com/auth/analytics.readonly",
  deployed_url = "",
  local_folder = "",
  ...
)

Arguments

models

The ga_model file location ("my_model.gamr") or a ga_model object - can pass in multiple as a list

template

The template Shiny files for the Shiny app - passed to shiny::runApp()

header_boilerplate

Whether to add header boilerplate to the template

title

The title of the Shiny app

auth_dropdown

What type of account picker to include

web_json

The client.id json file for Web

date_range

Most templates support a date_range global input for the data import functions, set this to FALSE to remove it

scopes

The scope the API requests will be under

deployed_url

If deploying Shiny app to a server, put the URL of the deployed app here so the authentication will redirect to the correct place

local_folder

If not empty, will not launch Shiny app but write code to the folder location you put here

...

Extra macro variables the template may support: a named list with the name being a template variable

Details

As ga_model objects have standardised code, they can be used to build standard templated Shiny apps. Templates are made using the whisker.render function

Some templates are included with the package, seen via ga_model_shiny_template("list")

Templates hold macro variables indicated via {{ macro_name }} in the Shiny app template code. See ga_model_shiny_template("basic_app", TRUE) for an example showing a minimal viable app. Templates can be files such as ui.R or app.R files; folders containing ui.R, app.R files; or ui.R with html files for advanced themes - see Shiny HTML templates. All additional files that may be in the folder are also copied over (such as global.R or www/ folders)

Templates contain code to allow multi-user login via Google OAuth2.

If your template is pointing at a file such as ui.R or app.R it will create an app.R Shiny object. If your template is pointing at a directory it will check for the presence of ui.R within the folder. In either case if the server.R is missing it will use the boilerplate version from ga_model_shiny_template("boilerplate")

By default the Shiny app is launched which in most cases will prompt authorisation for your Google Analytics. You can instead write the app out using local_folder to a valid location for deployment later.

Template macro variables

See Also

Other GA modelling functions: ga_model_edit(), ga_model_example(), ga_model_load(), ga_model_make(), ga_model_save(), ga_model_shiny_load(), ga_model_shiny_template(), ga_model_write(), ga_model()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# see Shiny templates included with the package
ga_model_shiny_template("list")

# see an example of an ui.R template with macros
ga_model_shiny_template("basic/ui.R", read_lines = TRUE)

# see an example of an app.R template with macros
ga_model_shiny_template("basic_app/app.R", read_lines = TRUE)

## Not run: 

# a universal analytics model using default template "basic"
ga_model_shiny(
  ga_model_example("decomp_ga.gamr"), 
  auth_dropdown = "universal")

# a template from a directory holding an app.R file
ga_model_shiny(
  ga_model_example("decomp_ga.gamr"), 
  auth_dropdown = "universal",
  template = ga_model_shiny_template("basic_app"))
  
  
# a template from only an ui.R file that will import boilerplate server.R
ga_model_shiny(
  ga_model_example("decomp_ga.gamr"), 
  auth_dropdown = "universal",
  template = ga_model_shiny_template("basic/ui.R"))

# a template from a custom html based theme
ga_model_shiny(
  ga_model_example("decomp_ga.gamr"), 
  auth_dropdown = "universal",
  template = ga_model_shiny_template("html_based"))

# a template using library(argonDash)
ga_model_shiny(
  ga_model_example("ga-effect.gamr"), 
  title = "Argon Demo",
  auth_dropdown = "universal",
  template = ga_model_shiny_template("argonDash") )

# multiple models
m3 <- ga_model_example("time-normalised.gamr")
m4 <- ga_model_example("ga-effect.gamr")

# launch in gentelella template
ga_model_shiny(list(m4, m3), auth_dropdown = "universal",
              template = ga_model_shiny_template("gentelella"))

     
# you can make custom ui embedded within the template file
# use {{{ model_list }}} to work with the models in the ui.R

# below adds custom macro 'theme' and a custom ui in box tabs
ga_model_shiny(list(m4, m3), auth_dropdown = "universal", 
               template = ga_model_shiny_template("shinythemes"), 
               theme = "yeti")

# shinydashboard's custom ui functions put a model in each side tab      
ga_model_shiny(list(m4, m3), auth_dropdown = "universal", 
               template = ga_model_shiny_template("shinydashboard"), 
               skin = "green")
               
# send in lots of theme variables to bslib in shiny > 1.6.0
ga_model_shiny(list(m4, m3), auth_dropdown = "universal",
               template = ga_model_shiny_template("basic_bslib"), 
               bg = "white", fg = "red", primary = "grey")
 
# write out an app to a local folder
ga_model_shiny(list(m4, m3), auth_dropdown = "universal",
               template = ga_model_shiny_template("basic_bslib"), 
               bg = "white", fg = "red", primary = "grey",
               local_folder = "deploy_shiny")

## End(Not run)

googleAnalyticsR documentation built on Oct. 7, 2021, 9:06 a.m.