Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gar_shiny_auth

Create Authentication within Shiny's server.R


Description

This can be used at the top of the server function for authentication when you have used gar_shiny_ui to create a login page for your ui function.

In some platforms the URL you are authenticating from will not match the Docker container the script is running in (e.g. shinyapps.io or a kubernetes cluster) - in that case you can manually set it via 'options(googleAuthR.redirect = http://your-shiny-url'). In other circumstances the Shiny app should be able to detect this itself.

Usage

gar_shiny_auth(session)

Arguments

session

Shiny session argument

Details

If using gar_shiny_ui, put this at the top of your server.R function

Author(s)

Based on a gist by Joe Cheng, RStudio

See Also

Other pre-load shiny authentication: gar_shiny_auth_url(), gar_shiny_login_ui(), gar_shiny_ui(), silent_auth()

Examples

## Not run: 
library(shiny)
library(googleAuthR)
gar_set_client()

fileSearch <- function(query) {
  googleAuthR::gar_api_generator("https://www.googleapis.com/drive/v3/files/",
                                "GET",
                                pars_args=list(q=query),
                                data_parse_function = function(x) x$files)()
}

## ui.R
ui <- fluidPage(title = "googleAuthR Shiny Demo",
                textInput("query", 
                label = "Google Drive query", 
                value = "mimeType != 'application/vnd.google-apps.folder'"),
                tableOutput("gdrive")
                )
                
## server.R
server <- function(input, output, session){

# this is not reactive, no need as you only reach here authenticated
gar_shiny_auth(session)

output$gdrive <- renderTable({
  req(input$query)
  
  # no need for with_shiny()
  fileSearch(input$query)
  
  })
  }

# gar_shiny_ui() needs to wrap the ui you have created above.
shinyApp(gar_shiny_ui(ui), server)

## End(Not run)

googleAuthR

Authenticate and Create Google APIs

v1.4.0
MIT + file LICENSE
Authors
Mark Edmondson [aut, cre] (<https://orcid.org/0000-0002-8434-3881>), Jennifer Bryan [ctb], Johann deBoer [ctb], Neal Richardson [ctb], David Kulp [ctb], Joe Cheng [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.