Learn R Programming

shinyga (version 0.1.2.9001)

doAuthMacro: Quick setup of shinyGA authentication

Description

This function calls all the other authentication functions so you can quick start. Sacrifices customisation for speed.

Usage

doAuthMacro(input, output, session, securityCode, client.id, client.secret, type = "analytics", customScopes = NULL)

Arguments

input
Shiny input object.
output
Shiny output object.
session
Shiny session object.
securityCode
A unique session code, such as from createCode()
client.id
The client ID taken from the Google API Console.
client.secret
The client secret taken from the Google API Console.
type
Type of Google Authentication. c("analytics").
customScopes
If not NULL, then a chacter vector of Google scopes to authenticate.

Value

For Analytics:A named list. See example for uses in shinyServer().
token
Google Authentication Token needed for API calls.
table
Table of Google Analytics Profiles needed for rollupGA.
It also outputs the link users need to click on to authenticate as output$AuthGAURL. Put this in your ui.r somewhere by using uiOutput("AuthGAURL")For Analytics, the function will also create the outputs for an authentication menu. The user needs to choose their Account, Web Property and View for the GA API to work. The menu outputs are per the defaults of renderAuthDropdownRowAlso outputs a DataTable called 'output$GAProfile' for use in ui.r as renderDataTable('GAProfile')

See Also

Authentication macros renderAuthDropdownRow and authDropdownRow

Other authentication functions: authReturnCode; createCode; shinygaGetTokenURL; shinygaGetToken

Examples

Run this code
## Not run: 
# 
# securityCode <- createCode()
# 
# shinyServer(function(input, output, session)){
# 
#   ## returns list of token and profile.table
#   ## client info taken from Google API console.
#   auth <- doAuthMacro(input, output, session,
#                       securityCode,
#                       client.id     = "xxxxx.apps.googleusercontent.com",
#                       client.secret = "xxxxxxxxxxxx",
#                       type          = "analytics"
#                       )
# 
#   ga.token         <- auth$token
#   profile.table    <- auth$table
# 
#   ## call the token for API calls
# 
#   gadata <- reactive({
# 
#     rollupGA(GAProfileTable = profile.table(),
#              dimensions     = 'ga:date',
#              start_date     = '2014-03-13',
#              end_date       = '2015-03-13'
#              metrics        = 'ga:sessions',
#              ga             = ga.token())
#                  })
# 
#   }
# ## End(Not run)

Run the code above in your browser using DataLab