Shiny Server Quick Start: Host an Application Supported by Multiple R Processes (Pro only)


This article is adapted from the Shiny Server Administrator's Guide for version 1.4.2.


Since the Utilization Scheduler is being used in this scenario, this configuration is only valid for Shiny Server Professional installations.

You can configure Shiny Server Professional to run multiple Shiny processes for a single application. You could choose to distribute incoming traffic evenly across up to three processes (the default), or even create a separate Shiny process for each incoming user. The configuration details for this setup are discussed in the section on the Utilization Scheduler.

Shiny Server is configured by a file stored at /etc/shiny-server/shiny-server.conf. in this Quick Start guide, we will be using a shiny-server.conf file that contains the following:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Specify the authentication method to be used.
# Initially, a flat-file database stored at the path below.
auth_passwd_file /etc/shiny-server/passwd;

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define the location available at the base URL
  location / {
# Only allow up to one connection per Shiny process, and at most five # Shiny processes per application. utilization_scheduler 1 .7 5; # Host the directory of Shiny Apps stored in this directory site_dir /srv/shiny-server; # Log all Shiny output to files in this directory log_dir /var/log/shiny-server; # When a user visits the base URL rather than a particular application, # an index of the applications available in this directory will be shown. directory_index on; } } # Define a default admin interface to be run on port 4151. admin 4151 { # Restrict the admin interface to the usernames listed here. Currently # just one user named "admin" required_user admin; }

Lines beginning with a # are treated as comments and not parsed when configuring the server.

This configuration defines a single location at the base URL (/), where a directory of applications would be hosted from the /srv/shiny-server directory.  It also includes the following line to specify that a Utilization Scheduler should be used when serving Shiny applications:

utilization_scheduler 1 .7 5;

This setting would create a Utilization Scheduler for this application that would support a maximum of 5 processes, a maximum of 1 connection per process, and a load factor of 70%, meaning that once once 70% of the connections per process were used, a new R process would be spawned.  In this case, since only one connection is allowed per process, a new process would be spawned for each new connection, up to 5 total processes for each application.

This configuration would be appropriate for an application that is computationally intensive. In such an application, one session may tie up the Shiny process for minutes at a time with computation, which would create an unpleasant experience for other users trying to connect to the same process during that window. With this configuration, we can ensure that each user gets his or her own designated Shiny process.

You should be able to connect to the Shiny Server sample application from a browser by visiting a URL like http://<server-address>:3838/<app-name>, where the application files are stored in the srv/shiny-server/app-name directory on the server.

To inspect the processes that are being created, and understand how they are performing, you can open Shiny Server's Admin Dashboard. Before you can log in to the dashboard, you must create a user who is allowed to access the Dashboard. Shiny Server Pro comes with multiple different methods of authenticating users (as described in the Authentication & Security section of the Shiny Server Administrator's Guide). Out of the box, it is configured to use a Flat-File Authentication database stored in /etc/shiny-server/passwd. This database is initially empty; to create a user named admin, execute the following command:

$ sudo /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd admin

then enter the new password for the admin user when prompted. Once completed, you will have a single user defined in your database named admin.

You should now be able to log in to your administrative dashboard at the URL http://<server-address>:4151/ with the username admin and the password you just created. See Admin section of the Shiny Server Administrator's Guide for more details on how to take advantage of this interface.

You can monitor the processes that are being created in real-time using the Admin Dashboard. You can also drill down into each process to verify that the connections are being assigned to their own private Shiny processes as expected.