Shiny is an R package that allows users to convert R code into interactive web pages. Shiny server is a server provided by RStudio, which can be used to host and manage Shiny applications on the Web. In addition to hosting Shiny applications, Shiny Server can also host [Interactive R Markdown Documents] (http://rmarkdown.rstudio.com/). Shiny Server has both a free open source version and a paid professional version with more features.
In this guide, we will learn how to set up an open source Shiny Server on Tencent CVM running Ubuntu 14.04. If your CVM is running a different version of Ubuntu or a different Linux distribution, most of the instructions still apply, but you may need to modify some commands to match your specific distribution. You can also use this guide to set up Shiny Server Professional. It will take about 10-15 minutes after completing this guide.
In this tutorial, you will need:
All commands in this tutorial should be run as a non-root user. If the command requires root access, it will have sudo
in front.
**Note: **In the rest of this guide, when you see the IP of your server, you need to replace it with the IP of your CVM.
Before installing Shiny Server, we need to install the shiny R package. We will install shiny
in a way to make it available to all users on the server.
sudo su --c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""
**Note: **If you are familiar with R, you may want to install packages directly from R instead of from the command line. The method used here is the safest way to ensure that the installed package is installed for all users, not just the user currently running R.
We will install Shiny Server using the GDebi tool, so first we need to install it.
sudo apt-get install gdebi-core
Now we are ready to download Shiny Server. Assuming your CVM is running 64-bit Ubuntu, use the following command to download Shiny Server.
wget -O shiny-server.deb http://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.3.0.403-amd64.deb
This will download Shiny Server version 1.3.0.403, which is the latest Shiny Server at the time of writing. If you want to download the latest version, you can check the official Shiny Server download page to find the latest version and change the URL accordingly. If you are running a 32-bit operating system or a non-Ubuntu distribution, you may need to refer to the Shiny Server download page, for specific instructions on the operating system.
Now use GDebi to install the downloaded file.
sudo gdebi shiny-server.deb
Shiny Server should now be installed and running on port 3838
. You should be able to on http://your_server_ip:3838/
See the default welcome screen.
You can visit http://your_server_ip:3838/sample-apps/hello/
to ensure that your Shiny Server is working properly.
Shiny Server can be used not only to host Shiny applications, but also to host interactive R markdown documents. You can learn more about the interactive R markdown document on the official Rmarkdown website of RStudio.
At this point you should have a working Shiny Server that can host Shiny applications, but since the rmarkdown
R package is not installed, it cannot yet host interactive R markdown documents. Shiny Server comes with a sample interactive document, which can be obtained from the following http://your_server_ip:3838/sample-apps/rmd/
location. If you go to that URL now, you will see an error.
Let's install the rmarkdown
package to fix it.
sudo su --c "R -e \"install.packages('rmarkdown', repos='http://cran.rstudio.com/')\""
Shiny Server is now set to run interactive R markdown documents and Shiny applications. To verify that the interactive document is valid, go to http://your_server_ip:3838/sample-apps/rmd/
and make sure there are no errors.
If you have purchased a Shiny Server Professional license and want to use the license on this server, only perform this step.
After purchasing the license, RStudio will provide you with the URL to download the Shiny Server Pro file. Download the Shiny Server Pro file.
wget -O shiny-server-pro.deb Shiny_Server_Pro_URL
Install Shiny Server Pro.
sudo gdebi shiny-server-pro.deb
You will also get the product key required to activate Shiny Server Pro.
sudo /opt/shiny-server/bin/license-manager activate Product_Key
Restart Shiny Server Pro to start the activated version.
sudo reload shiny-server
You now have a powerful Shiny Server that can host Shiny applications or interactive documents. The configuration file of Shiny Server is located in /etc/shiny-server/shiny-server.conf
. By default, it is configured to serve applications in the /srv/shiny-server/
directory. This means that all Shiny applications placed will be available to the public, and the public can visit /srv/shiny-server/app_name, http://your_server_ip:3838/app_name/
to get them.
It is best to check Shiny Server Administrator's Guide to learn how to customize the server according to your exact needs and how to manage the server.
To learn more about writing Shiny applications, please read Tutorial on rstudio.com.
To learn more about writing interactive R markdown documents, check out the R Markdown page on rstudio.com.
In this guide, we have completed the steps required to set up Shiny Server on Ubuntu 14.04 Tencent CVM. By setting up Shiny Server, we can host Shiny applications and interactive R documents on the Web in a publicly accessible way.
For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.
Reference: "How To Set Up Shiny Server on Ubuntu 14.04"
Recommended Posts