Basic Ubuntu commands for RStudio Shiny users

[This article was first published on R – MYHAPPYDATA BLOG, 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.

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. shinyapps.io 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 https://cran.rstudio.com/
sudo su - -c "R -e \"install.packages('ggplot2', repos='https://cran.rstudio.com/')\""
 
# 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
ls
 
# 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 Your 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:

To leave a comment for the author, please follow the link and comment on their blog: R – MYHAPPYDATA BLOG.

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)