Learn R Programming

shinymanager (version 1.0)

secure-app: Secure a Shiny application and manage authentication

Description

Secure a Shiny application and manage authentication

Usage

secure_app(ui, ..., enable_admin = FALSE, head_auth = NULL,
  theme = NULL, language = "en")

secure_server(check_credentials, timeout = 15, session = shiny::getDefaultReactiveDomain())

Arguments

ui

UI of the application.

...

Arguments passed to auth_ui.

enable_admin

Enable or not access to admin mode, note that admin mode is only available when using SQLite backend for credentials.

head_auth

Tag or list of tags to use in the <head> of the authentication page (for custom CSS for example).

theme

Alternative Bootstrap stylesheet, default is to use readable, you can use themes provided by shinythemes. It will affect the authentication panel and the admin page.

language

Language to use for labels, supported values are : "en", "fr".

check_credentials

Function passed to auth_server.

timeout

Timeout session (minutes) before logout if sleeping. Defaut to 15. 0 to disable.

session

Shiny session.

Value

A reactiveValues containing informations about the user connected.

Examples

Run this code
# NOT RUN {
if (interactive()) {

  # define some credentials
  credentials <- data.frame(
    user = c("shiny", "shinymanager"),
    password = c("azerty", "12345"),
    stringsAsFactors = FALSE
  )

  library(shiny)
  library(shinymanager)

  ui <- fluidPage(
    tags$h2("My secure application"),
    verbatimTextOutput("auth_output")
  )

  # Wrap your UI with secure_app
  ui <- secure_app(ui)


  server <- function(input, output, session) {

    # call the server part
    # check_credentials returns a function to authenticate users
    res_auth <- secure_server(
      check_credentials = check_credentials(credentials)
    )

    output$auth_output <- renderPrint({
      reactiveValuesToList(res_auth)
    })

    # your classic server logic

  }

  shinyApp(ui, server)

}
# }

Run the code above in your browser using DataLab