A simple walkthrough to install and configure an RStudio’s RShiny server on Centos 7. I’m assuming you already have R installed, if you don’t head on over to my post on installing R on Centos 7

As always, this is as much documentation for me as it is intended to be a tutorial but suggested corrections, additions and omissions are welcomed.

1. Download

First install the R package shiny:

sudo su - -c "R -e \"install.packages('shiny', repos = 'https://cran.rstudio.com/')\""

Now download RShiny Server:

wget https://download3.rstudio.org/centos5.9/x86_64/shiny-server-1.5.1.834-rh5-x86_64.rpm

And install:

sudo yum install -y --nogpgcheck shiny-server-1.5.1.834-rh5-x86_64.rpm

Shiny Server is now installed! Verify with:

service shiny-server status
# Redirecting to /bin/systemctl status  shiny-server.service
# ● shiny-server.service - ShinyServer
#   Loaded: loaded (/etc/systemd/system/shiny-server.service; enabled; vendor preset: disabled)
#   Active: active (running) since Sat 2017-02-25 11:27:01 EST; 3min 42s ago
#  Process: 19059 ExecStartPost=/usr/bin/sleep 3 (code=exited, status=0/SUCCESS)
# Main PID: 19060 (shiny-server)
#   CGroup: /system.slice/shiny-server.service
#           ├─19058 /usr/bin/bash -c /opt/shiny-server/bin/shiny-server --pidfile=/var/run/shiny-server.pid >> /var/log/shiny-server.log 2>&1
#           └─19060 /opt/shiny-server/ext/node/bin/shiny-server /opt/shiny-server/lib/main.js --pidfile=/var/run/shiny-server.pid

# Feb 25 11:26:58 IMPERATORIS2 systemd[1]: Starting ShinyServer...

Other options for starting, stopping and restating can be found in this section of the guide.

2. Configuration

To configure the service use the immensely helpful Administrators Guide from RStudio.

The default configuration file can be found at /etc/shiny-server/shiny-server.conf:

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

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

  # Define a location at the base URL
  location / {

    # 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;
  }
}

I tend to leave these as-is and use the directory structure underneath /srv/shiny-server dictate the organization and protect certain paths with 0Auth from Nginx.

Firewall

You’ll need to open the firewall for that port:

sudo firewall-cmd --zone=public --add-port=3838/tcp --permanent
# success
sudo firewall-cmd --reload
# success

Check that you have access by going to <your-ip>:3838, you should see this page:

default shiny server index file

You can also test out access to apps by going to <your-ip>:3838/sample-apps/hello/. If you can see it, you’re ready to start serving up your apps!

Port Forwarding

The rest here is my personal preference and is as such, completely optional.

Since I use Shiny Server to host static content as well, I like to set up forwarding of incoming unsecured traffic to the port on which I’m serving up Shiny apps on:

sudo firewall-cmd --zone=public --add-masquerade --permanent
# success
firewall-cmd --zone=public --add-forward-port=port=80:proto=tcp:toport=3838 --permanent
# success
sudo firewall-cmd --reload
# success

Now you can give URLs without specifying the port, e.g. <your-ip>/sample-apps/hello/, which to me is a subtle but important feature governing ease of use for the app.

port forwarded shiny app url

Hope this was helpful!