Basic Ubuntu commands for RStudio Shiny users

RStudio Shiny is a great tool to create interactive reports and dashboards for R users. There are many ways to publish the results, e.g. is a free online platform but sooner or later it is recommended to install it to a Linux server especially at an enterprise level usage. By the way I use a DigitalOcean VPS (this is a referral link) mainly for practice and to find a place for my free time projects. At the very first period it is best to improve your Linux skills on a virtual server (Oracle VM Virtual Box) because it is totally free and you cannot ruin anything.

Shiny needs a Linux environment so it is recommended to learn at least the basic commands. I use Ubuntu 16.04 server so commands may vary on different Linux distributions. There are great tutorials how to install and configure Linux servers here are some recommended materials:

In the followings I collected the basic Linux commands which are good to know for Shiny Server administrators or owners:

install R packages from terminal to all users. It is quite rare that Shiny apps does not need any external packages so It is a useful command.

# install package 'ggplot2' from
sudo su - -c "R -e \"install.packages('ggplot2', repos='')\""

# install package dplyr from Github
# you have to install the package devtools at first before using this command.
sudo su - -c "R -e \"devtools::install_github('hadley/dplyr')\""

Install, uninstall Linux packages Sometimes you have to install other Linux packages to use R packages (e.g. package Cairo needs libcairo2-dev and libxt-dev)

# install mysql-server
sudo apt-get install mysql-server

# uninstall mysql-server
sudo apt-get purge mysql-server

Upgrade currently installed packages Soon or later previously installed packages need to be updated (e.g. R) if there is a new available version.

# updating the package list
sudo apt-get update

# upgrade installed packages
sudo apt-get upgrade

Modify Shiny config file When you move files from your computer to the Server it is recommended to Use an FTP tool (e.g. FileZilla) but if some command lines needs to be modified it is best to use some built in Linux text editor. I use VIM here is the basic tutorial of it. Here is more information about the config file.

# navigate to a specific folder.
cd /etc/shiny-server/

# optional: create a backup if it is needed
cp shiny-server.conf shiny-server-backup.conf

# open config file and modify it and save (hit the esc key and type: ':x' to quit).
sudo vim shiny-server.conf

Check Shiny Server logs It is a little bit trickier to fix a bug because you have to check the log files to find what is the problem with the application.

# navigate to the folder of Shiny Server logs
cd /var/log/shiny-server

# print the list of the files of the current folder

# open the file named 'testapp-shiny-20170729-065006-33136.log' (Copy a file name: all you have to do is left click and drag to make a selection and than simply right-click to paste)
# type 'q' to quit
less testapp-shiny-20170729-065006-33136.log

Change permissions According to r Linux Server settings you need to change the ownership of files or folders e.g. to update the R scripts if somebody else uploaded it earlier.

# change the owner of the folder '/srv/shiny-server/test_app'. The new owner is user1.
chown -R user1 /srv/shiny-server/test_app

Finally some useful course for a deeper knowledge: