User authentication in R Shiny – sneak peek of shiny.users and shiny.admin packages
This article is originally published at https://appsilon.com

Update August 2020: We are sorry to inform you that shiny.users package development has been suspended. We currently have no plans to continue development. Although there is significant interest in a Shiny authorization package, the effort to maintain and improve our early release was unsustainable and we decided to use this time on our other open-source packages such as shiny.semantic. Don’t worry though, there are existing tools for user authorization and authentication on the market that you can use: shinyapps.io, Shiny Server Pro, R Studio Connect, auth0 package (with our Auth0 management API), using nginx and several others. If any of the available solutions on the market do not respond to your needs, please contact us – [email protected] We offer bespoke solutions for enterprise and non-standard Shiny applications.
We decided to share the early release of shiny.stats package that was initially part of shiny.admin package development. It’s an easy way for logging users activity and adding a statistics panel to your Shiny app. [/Update]
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_sha256 = "A7574A42198B7D7EEE2C037703A0B95558F195457908D6975E681E2055FD5EB9",
roles = list("basic", "admin")
),
list(
username = "john",
password_sha256 = "C2F77349B4D0CDE5A1E865195A9E395E1DF8829BE9D31707BD12F44CEB384A60",
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 an admin panel under the URL http://application-url/#!/admin
. This panel is only accessible by users with an “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 the 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]
Article User authentication in R Shiny – sneak peek of shiny.users and shiny.admin packages comes from Appsilon | End to End Data Science Solutions.
Thanks for visiting r-craft.org
This article is originally published at https://appsilon.com
Please visit source website for post related comments.