Installing RStudio & Shiny Servers

[This article was first published on R | datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I did a remote install of Ubuntu Server today. This was somewhat novel because it’s the first time that I have not had physical access to the machine I was installing on. The server install went very smoothly indeed.

The next tasks were to install RStudio Server and Shiny Server. The installation process for each of these is well documented on the RStudio web site:

These are my notes. Essentially the same, with some small variations.

RStudio Server

  1. Install a recent version of R.
  2. Download the distribution.

    wget https://download2.rstudio.org/server/trusty/amd64/rstudio-server-1.2.1335-amd64.deb
  3. Install the server.

    sudo dpkg -i rstudio-server-1.2.1335-amd64.deb

    If this generates an error you can run the following then try again.

    sudo apt-get --fix-broken install
  4. Verify the installation.

    sudo rstudio-server verify-installation
  5. RStudio Server runs on port 8787, so you should be able to access it in a browser at http://<server-ip>:8787.

Whether or not to Start at Boot

RStudio Server does not consume an awful lot of RAM. But on a small machine, every bit of memory can be precious. So perhaps you don’t want to have RStudio Server running all the time? No problem!

# Check whether RStudio Server is running.
systemctl is-active rstudio-server

# Disable RStudio Server at boot.
sudo systemctl disable rstudio-server

# Enable RStudio Server at boot.
sudo systemctl enable rstudio-server

You can then start and stop RStudio Server as and when required.

# Start RStudio Server.
sudo systemctl start rstudio-server

# Stop RStudio Server.
sudo systemctl stop rstudio-server

# Stop and then start RStudio Server.
sudo systemctl restart rstudio-server

Configuration Options

Configuration settings are stored in /etc/rstudio/rserver.conf.

One of the most common configuration changes that I make is to change the port on which RStudio Server is running. This can be done by adding the following line to the above configuration file:

www-port=80

Another thing you might want to tweak is the auth-minimum-user-id option, which determines the minimum UID which is allowed to login to RStudio Server. If you are having trouble with the shiny user logging in, then this is most likely to be the problem.

After making any changes to the configuration you need to restart the server.

Find out more about configuring and managing the server.

Shiny Server

  1. Become root and install the shiny package.

    sudo su
    R -e "install.packages('shiny', repos='https://cran.rstudio.com/')"
    exit
  2. Download the distribution.

    wget https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.9.923-amd64.deb
  3. Install the server.

    sudo dpkg -i shiny-server-1.5.9.923-amd64.deb
  4. Shiny Server runs on port 3838, so you should be able to access it in a browser at http://<server-ip>:3838.

Whether or not to Start at Boot

You can also disable Shiny Server being automatically started at boot.

# Disable Shiny Server at boot.
sudo systemctl disable shiny-server

You can then start and stop Shiny Server as and when required.

# Start Shiny Server.
sudo systemctl start shiny-server

# Stop Shiny Server.
sudo systemctl stop shiny-server

# Stop and then start Shiny Server.
sudo systemctl restart shiny-server

Shiny Configuration

You can edit the configuration file, /etc/shiny-server/shiny-server.conf, to tweak the settings of the Shiny server.

run_as shiny;                          # User used to run apps.

server {
  listen 3838;                         # Which port to listen on.
  app_init_timeout 600;                # How long to allow for startup (seconds).
  preserve_logs true;
  location / {
    site_dir /srv/shiny-server;        # Folder for installing apps.
    log_dir /var/log/shiny-server;     # Folder for logs.
    directory_index on;                # What to do when user visits the base URL.
  }
}

Installing Apps

You should install apps into folders below /srv/shiny-server. Also ensure that all of the files in the app (source) are owned by shiny.shiny (if you don’t then the logs will simply disappear!).

To leave a comment for the author, please follow the link and comment on their blog: R | datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)