12 Shiny

12.1 User meta-data

Shiny applications can access the username and groups of the current user through the session parameter of the shinyServer function.

Group meta-data is populated when using most authentication providers, except LDAP. This happens because group memberships are only stored in the LDAP server.

shinyServer(function(input, output, session) {
  output$username <- reactive({
  output$groups <- reactive({

Your application could use this information to display customized messages or to enable functionality for a specific subset of users.


Version 0.14 of the shiny package introduced bookmarkable state. RStudio Connect includes full support for Shiny’s bookmarkable state features. Bookmarkable state allows users to create and share custom URLs to Shiny applications that will automatically restore the inputs and outputs of an application. For example, a user may select a set of inputs that produces an interesting plot. Rather than instructing another user to click through the same input steps to view the plot, they can create a bookmarked URL and share the URL with others. For more information, visit the Shiny Development Center.

12.3 Plot Caching

Version 1.2 of the shiny package introduced plot caching. Plot caching can greatly improve the performance of an application visited by multiple users. Plot caching prevents the R process from re-creating identical plots for each visitor.

To use plot caching, simply replace calls to shiny::renderPlot with a call to shiny::renderCachedPlot and include a shiny::cacheKeyExpr. View the help page for shiny::renderCachedPlot for details (run ?shiny::renderCachedPlot from R).

In addition to this change, applications deployed on RStudio Connect should use a disk cache and specify a subdirectory of the application directory as the location for the cache. To do so, add this code to the top of your application:

shinyOptions(cache = diskCache("./cache"))

This option ensures that cached plots will be saved and used across the multiple R processes that RStudio Connect runs in support of an application. In addition, this configuration results in the cache being deleted and reset when new versions of the application are deployed.

12.4 Load Testing

The runtime settings of a Shiny application control how processes are managed: when to start and stop processes in reaction to traffic demands.

This support article explains process scheduling and provides some guidelines when changing your own application settings. Details for each setting are included in the Runtime/Scheduler configuration appendix of the RStudio Connect Admin Guide.

Shiny applications can be load tested using the shinyloadtest R package. The package includes support for applications deployed on RStudio Connect and applications that require authentication.

12.5 Shiny Application Usage

Connect tracks information about visits to Shiny applications and the length of that visit. Visit and session information is available via an API that may be called by administrators and publishers. Publishers may only retrieve information about applications they own.

Learn about the recorded data in the Shiny Application Events section of the RStudio Connect Admin Guide.

Code examples showing how to access this data are in the User Activity API Cookbook recipes. The Connect Server API Reference documents each of the Instrumentation APIs used by the recipes.