Shiny Server and Shiny Server Pro - Allowing different libraries for different apps
By: Jeff Allen
This article describes two ways to configure applications to use different sets of libraries in Shiny Server.
- Method 1 relies on Shiny Server’s
exec_supervisorfeature. It will only work with Shiny Server Pro.
- Method 2 relies on Shiny Server’s
run_asfeature. It will work with both Shiny Server and Shiny Server Pro.
Method 1 - exec_supervisor
With Shiny Server Pro, you can run R sessions under a program supervisor that modifies the environment of the sessions. You can use this supervisor to set the
R_LIBS_USER environmental variable, which controls which libraries a session may use.
Section 3.6 of the Shiny Server Administrator’s Guide explains how to add a program supervisor. You add an
exec_supervisor setting to your server config file to specify a supervisor (and the arguments which control its behavior).
The file below uses
exec_supervior to modify the default /etc/shiny-server/shiny-server.conf file that ships with Shiny Server.
exec_supervisor partitions the applications up by setting the
R_LIBS_USER environment variable.
Near the bottom of the file, a
/finance sub-location is defined for apps that use a specific set of libraries. Beneath that, a specific app is given its own set of libraries.
In this case, you could set up as many different libraries as you want and specify a different library for each location, or even each application that you want to deploy. This would give you fine-grained control over each of your applications.
Method 2 - run_as
Shiny Server (and Shiny Server Pro) use a
run_as setting to determine which user should spawn each R Shiny processes. The user setting determines which library R will look in for packages (as well as which directories the app will be able to read and write to).
run_as setting can be configured globally, or for a particular server or location. As a result, you can set up different locations for hosting apps that use different packages. Each location can be affiliated with its own user—each of which presumably has a different set of libraries specified with a ~/.Rprofile file.
With this approach, you would probably have only a handful of users that you create that each maintain their own separate libraries.
The file below uses
run_as to modify the default /etc/shiny-server/shiny-server.conf file that ships with Shiny Server.
run_asdefines a global user,
shiny, for the server. It then defines a different user for the
shinyFinance. The finance department can deploy apps in this location. Those apps will be restricted to the packages in the library of
shinyFinance, which may be different than the packages in the library of the user named
If you have questions about this article or would like to discuss ideas presented here, please post on RStudio Community. Our developers monitor these forums and answer questions periodically. See help for more help with all things Shiny.