Shiny Server Quick Start: Run Shiny Server on multiple ports


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


This guide will describe how to run Shiny Server on multiple ports simultaneously, and also how to run a single server with multiple locations.

The authentication portions of this configuration 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:

# Instruct Shiny Server to run applications as the user ':HOME_USER:', where
# possible (this username only takes effect in locations managed by
# 'user_dirs'). In all other locations, we should fall back to the 'shiny' user.
run_as :HOME_USER: 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;

# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;

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

  # Define a location at the URL "/users"
  location /users {
    # Allow users to host their own apps in ~/ShinyApps
    # Optionally, you can restrict the privilege of hosting Shiny applications
    # only to members of a particular Linux group.
    # members_of shinyUsers;    

  # Define a location at the URL "/example1"
  location /example1 {
    app_dir /srv/shiny-server/sample-apps/hello;

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

  # Define a location at the base URL
  location / {
    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/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;

# Provide the admin interface 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 will run two servers: one on port 3838, and one on port 4949. A variety of different locations are defined with different hosting models.

The server running on port 3838 defines two locations. The first is at the URL /users, which makes user applications available using the user_dirs hosting model, as documented in the Host Per-User Application Directories section of the Shiny Server Administrator's guide.  Any applications in your home directory will be accessible via the /users location. The second location is at the URL /example1, and hosts a single application that should be stored in/srv/shiny-server/sample-apps/hello/.

The server running on port 4949 has one location at the base URL (/) that hosts all applications in the /srv/shiny-server directory.

With this configuration, you would be able to access applications in a variety of ways:

  • On the server running on port 3838, you have a user_dirs location at /users hosting your personal applications. You can access any applications in your home directory at the URL http://<server-address>:3838/users/<your_username>/<your_app_name>, where <your_username> is your Linux username.
  • Also on the server running on port 3838, you have a single application available at the /example1 location. The URL http://<server-address>:3838/example1 points to that application.
  • Finally, the server on port 4949 will host any application defined in /srv/shiny-server. For example, you can access the one that comes with Shiny Server at the URL http://<server-address>:4949/sample-apps/hello.