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()
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.
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.
library(devtools)
## install shinydashboard dependency
devtools::install_github("rstudio/shinydashboard")
## install shinyga
devtools::install_github("MarkEdmondson1234/shinyga")
library(shiny)
library(shinydashboard)
library(shinyga)
?shinyga
Get your client secret, ID from the Google API console
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. http://127.0.0.1:1234
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. https://mark.shinyapps.io/ga-effect/
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.
Examples of minimal working examples are shown below, for you to adapt.
###### server.r
library(shiny)
library(shinydashboard)
library(shinyga)
securityCode <- createCode()
shinyServer(function(input, output, session){
## returns list of token and profile.table ----------------------------------
auth <- doAuthMacro(input, output, session,
securityCode,
## client info taken from Google API console.
client.id = "xxxxx.apps.googleusercontent.com",
client.secret = "xxxxxxxxxxxx",
type = "analytics")
## auth returns auth$table() and auth$token() to be used in API calls.
## get the GA data ----------------------------------------------------------
gadata <- reactive({
validate(
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)
data[,c('date','sessions')]
})
## do a plot! ---------------------------------------------------------------
output$gaplot <- renderPlot({
validate(
need(gadata(), "Authenticate to see"))
plot(gadata(), type="l")
})
})
##### ui.r
library(shiny)
library(shinydashboard)
library(shinyga)
dashboardPage(
dashboardHeader(
title = "Shiny Google Authentication demo",
dropdownMenuOutput("messageMenu")
),
dashboardSidebar(
sidebarMenu(
menuItem("Tab1", tabName = "setup", icon = icon("gears")),
menuItem("Tab2", tabName = "dash", icon = icon("dashboard")))
),
dashboardBody(
uiOutput("AuthGAURL"),
authDropdownRow(),
plotOutput("gaplot")
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.