shinyga - Shiny Google Authentication. Quick start user authentication for Google Analytics
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

shinyga (Shiny Google Authentication)

Easier Google Authentication Dashboards in Shiny.

The functions in the package were used to help create these demo apps:

Get in touch if you have any dashboards made with this package to get a link from here


I would now recommend that for Shiny apps using Google Analytics to use googleAnalyticsR as it has more features and is compatible with other Google APIs written with googleAuthR.

No new features will be added to shinyga()

Change history

Dev version

  • Integrating googlesheets authentication
  • GA users.

Version 0.1.2 - May 25th 2015

  • Added GA filters, custom metrics, Adwords API listings

Version 0.1.1 - March 27th 2015

  • Fixed bug where older GA accounts couldn't fetch segments or goals.
  • Port everything to httr, get rid of RCurl, RJSONIO
  • Segments will default to default GA ones if it can't find or parse yours
  • Removed need for redirect URL in Auth macro, Shiny will detect App URL from session info.

Version 0.1.0 - March 18th 2015

  • Initial Release


Please tell me any bugs or problems with examples or documentation in the issue tracker

Most functions have help files, start with ?shinyga

The package focused on quick setup of Google Authentication APIs, with initial focus on Google Analytics, so please keep that in mind when asking for features.

What shinyga does

Provides utility functions to help easily setup up a Google API authentication flow in Shiny. The focus is on Google Analytics initially, with macros to help easy download of GA data, but to be expanded later into other Google APIs such as Google Tag Manager, Gmail, BigQuery etc.



## install shinydashboard dependency

## install shinyga



To Use

Get Google API credentials

Get your client secret, ID from the Google API console

  • Create a Project
  • Go to APIs & Auth - Activate the appropriate Google API (only necessary for Analytics atm)
  • Go to APIs & Auth - Credentials.
  • Create new Client ID for web application
  • Note your Client ID and Client secret
  • Put the URL of your app in the Redirect URIs, one per line. See below.
  • Fill in some details on your consent screen

Client URL: Running Locally

For local the Shiny runApp() uses a random port, so specify using runApp(port=1234) and put that in the Google API console as your port number e.g.

Client URL: Running on Shiny Server or

If you use the doAuthMacro() functions it will detect your app URL for you, otherwise you will need to specify it via the redirect.uri parameter in the underlying authentication functions.

Use the URL where your app is published as your CLIENT_URL. You can put both your local and live URL in the Google API console.

TIP: Comment out the local one when you are ready to deploy. e.g.

Run Shiny

Read how to use Shiny apps before using this package.

This package also uses shinydashboard to make the pretty layout, but its not strictly necessary.

Shiny App Code Examples

Examples of minimal working examples are shown below, for you to adapt.

Google Analytics

###### server.r


securityCode <- createCode()

shinyServer(function(input, output, session){

  ## returns list of token and profile.table ----------------------------------
  auth <- doAuthMacro(input, output, session,
                      ## client info taken from Google API console.
                 = "",
                      client.secret = "xxxxxxxxxxxx",
                      type = "analytics")

  ## auth returns auth$table() and auth$token() to be used in API calls.

  ## get the GA data ----------------------------------------------------------
  gadata <- reactive({
      need(auth$token(), "Authentication needed"))

    df    <- auth$table()
    token <- auth$token()
    gaid  <- as.character(input$view)
    profileRow <- df[df$id %in% gaid,] 
    data <- rollupGA(GAProfileTable = profileRow,
                     dimensions = 'ga:date',
                     start_date = '2014-09-01',
                     metrics = 'ga:sessions',
                     end_date = '2015-03-01',
                     ga = token)

  ## do a plot! ---------------------------------------------------------------
  output$gaplot <- renderPlot({
      need(gadata(), "Authenticate to see"))

    plot(gadata(), type="l") 



##### ui.r


    title = "Shiny Google Authentication demo",
      menuItem("Tab1", tabName = "setup", icon = icon("gears")),
      menuItem("Tab2", tabName = "dash", icon = icon("dashboard")))