Shiny Server Quick Start: Host a directory of applications


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


This is the default configuration that Shiny Server will use until you provide a custom configuration in /etc/shiny-server/shiny-server.conf. This guide will show you how to serve multiple applications from a single directory on disk -- /srv/shiny-server/.

The utilization_scheduler and admin directives of this configuration file are only valid for Shiny Server Pro installations, though the location structure is valid on open-source installations, as well.

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:

# Define the user we should use when spawning R Shiny processes
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 top-level server which will listen on a port
server {
  # Instruct this server to listen on port 3838
  listen 3838;

  # Define the location available at the base URL
  location / {
    # Run this location in 'site_dir' mode, which hosts the entire directory
    # tree at '/srv/shiny-server'
    site_dir /srv/shiny-server;
    # Define where we should put the log files for this location
    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;

    # Only up to 20 connections per Shiny process and at most 3 Shiny processes
    # per application. Proactively spawn a new process when our processes reach 
    # 90% capacity.
    utilization_scheduler 20 .9 3;

# Define a default admin interface to be run on port 4151.
admin 4151 {
  # Only permit the user named `admin` to access the admin interface.
  required_user admin;

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

This configuration assumes your Shiny applications are hosted in /srv/shiny-server/, and will refer to a sample application in /srv/shiny-server/sample-apps/hello/. As defined, this Shiny Server listens on port 3838, so the sample application would be available at http://<server-address>:3838/sample-apps/hello/.

If you wanted to change the port Shiny Server uses, you would open/etc/shiny-server/shiny-server.conf in your preferred text editor, and modify the line that says listen 3838. This is the line that instructs your server to listen to port 3838 -- change it to another port such as 12345 and save the file. Then, restart Shiny Server to reload the configuration file. The Stopping and Starting section of the Admin Guide describes this process in detail, but for example, run this command if you are on a distribution that supports Upstart (most recent distributions, including Ubuntu 12 and later and CentOS 6):

sudo restart shiny-server

If you are on an older system that relies on init.d (such as CentOS 5), you will use the following command instead:

sudo /sbin/service shiny-server restart

You should now find that Shiny Server is no longer running on port 3838, but is on whichever new port you selected. Changing the directory in which the applications are hosted follows a similar pattern:  edit /etc/shiny-server/shiny-server.conf to replace the value in the site_dir directive, restart the server, and see your changes take effect.