Shiny Server is an open-source software that allows to self-host apps developed using Shiny package. This tutorial explains how to install Shiny Server on Ubuntu 20.04.
Before you begin the tutorial, you should:
yourdomain.tld
as an example.yourdomain.tld
and www.yourdomain.tld
which points to your server’s IP address. Follow the instructions at your domain registrar or use Vultr DNS.Install package dependencies.
sudo apt install software-properties-common dirmngr libgeos-dev libproj-dev libgdal-dev libxml2-dev libssl-dev libcurl4-openssl-dev
Add the signing key.
sudo wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
Add the R 4.0 repository from Comprehensive R Archive Network (CRAN).
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
Install the R package.
sudo apt install r-base-dev
Verify the installation.
$ R -e 'R.version'
version.string R version 4.1.3 (2022-03-10)
Install required compilers.
sudo apt install make gcc g++ cmake gfortran
Install Shiny package.
sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""
Install GDebi.
sudo apt install gdebi-core
Download Shiny Server.
sudo wget https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.17.973-amd64.deb
Install Shiny Server.
sudo gdebi shiny-server-1.5.17.973-amd64.deb
Install Nginx.
sudo apt install nginx
Enable TCP Port 80 and 443.
sudo ufw allow 'Nginx Full'
Allow traffic through to Shiny Server.
sudo ufw allow 3838
Verify if Shiny Server is running.
$ systemctl status shiny-server
Active: active (running)
Edit the Nginx configuration file.
sudo nano /etc/nginx/nginx.conf
Add the following lines(inside the existing http block) and save the file.
http {
...
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
Edit default Nginx server block.
sudo nano /etc/nginx/sites-enabled/default
Add the following lines above the server block and save the file.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
Add the following lines inisde the location block.
location / {
proxy_pass http://127.0.0.1:3838/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
Edit the server_name value and save the file.
server_name yourdomain.tld www.yourdomain.tld;
Test the new Nginx configuration.
sudo nginx -t
Restart Nginx to activate changes.
sudo systemctl restart nginx
Navigate to your domain URL and you should see Shiny Server.
https://yourdomain.tld
When you first navigate to your Domain URL there’s an error at the bottom right section. Install the missing rmarkdown
package.
sudo su - -c "R -e \"install.packages('rmarkdown', repos='http://cran.rstudio.com/')\""
You can install any necessary package using the below command. Replace package-name
with the actual package name.
sudo su - -c "R -e \"install.packages('package-name', repos='http://cran.rstudio.com/')\""
Create a new usergroup.
sudo groupadd shiny-apps
Add shiny user and non-root sudo user to the above created group. In this tutorial opsuser
is the non-root sudo user.
sudo usermod -aG shiny-apps opsuser
sudo usermod -aG shiny-apps shiny
Change ownership of Shiny Server apps directory.
cd /srv/shiny-server
sudo chown -R dean:shiny-apps .
Change directory permissions.
sudo chmod g+w .
sudo chmod g+s .
Shiny server serves apps from the /srv/shiny-server/
directory. Create the required app name and upload the shiny apps files. Navigate to yourdomain.tld/appname
to view your Shiny app.
https://yourdomain.tld/appname
This completes the steps to install Shiny Server and deploy Shiny apps on Ubuntu 20.04. For more information, refer to the official Shiny Server Administrator’s Guide.