Article Image
Article Image
read

At Appsilon we frequently build advanced R/Shiny dashboards that need user authentication. I would like to share with you how we implement user management - user accounts, the authorization process and gather usage statistics to have a better understanding of how the app is used.

For user authentication, we created the shiny.users package. For user administration and usage statistics, we created the shiny.admin package. We will show you a sneak peek of how these packages work. They are not released yet - but we opened an Early Adopter Waitlist - sign up and we will contact you as soon as these packages will be ready for production testing!

Shiny.users - convenient authentication on the application level

Here is an example of how shiny.users works when you add it to your shiny application:

Below you can view the code of this example:

library(shiny)
library(shiny.users)

demo_users <- list(
  list(
    username = "demo-appsilon", 
    password = "QZt85C46Ab", 
    roles = list("basic", "admin")
  ),
  list(
    username = "john", 
    password = "C4SRx3xJcy", 
    roles = list("basic")
  )
)

ui <- shinyUI(fluidPage(
  div(class = "container", style = "padding: 4em",
    login_screen_ui('login_screen'),
    uiOutput("authorized_content")
  )
))

server <- shinyServer(function(input, output) {
  users <- initialize_users(demo_users)
  callModule(login_screen, 'login_screen', users)

  output$authorized_content <- renderUI({
    if (!is.null(users$user()) {
      ... # application content
    }
  })
})

shinyApp(ui, server)

This is a simple demo with users defined in a list. In a real-world scenario, you would store user credentials in a database or authenticate users with an external API. This is also covered in shiny.users.

In bigger apps with more users, you will also need user management, authorization management (different roles e.g. admin, writer, reader, etc) and usage statistics. For such advanced use cases, we created shiny.admin package.

Shiny.admin - user management and usage statistics

This package is an extension to the shiny.users package. When you add it to your Shiny app, you instantly get admin panel under the url http://application-url/#!/admin. This panel is only accessible by the users with “admin” role.

Features of shiny.admin:

  • Adding and removing users
  • Managing existing users - their passwords, roles and metadata
  • Statistics - counting unique users and sessions (similar to Google Analytics)
  • Session recording - recording defined actions e.g. provided input values and clicked elements. You can view all sessions details (similar to Hotjar)

We observed huge gains from above features. We exactly understood how our apps were used by our users. Here are some screenshots from shiny.admin:

I hope you like the idea of shiny.users and shiny.admin packages. Let us know what would you expect from user accounts and admin panel features. Do you think there is a need for developing such packages? Tell us about your use cases and needs in the comments or contact us at [email protected]

Also, don’t forget to sign up to shiny.users and shiny.admin waitlist!

Follow Appsilon Data Science

Blog Logo

Paweł Przytuła


Published

Image

Appsilon Data Science Blog

Our secrets.

Back to the top