Shiny application in production with ShinyProxy, Docker and Debian

You created some great Shiny applications, following our advice of Shiny packaging for example, and you want to put them into production, self-hosting, so that others can enjoy them, without limitations, on the Internet or on an internal server of your company? ShinyProxy is for you!

ShinyProxy v2.0 has recently been released. What a great opportunity to talk about its implementation!
A major interest of ShinyProxy is its ability to create an independent Docker container for each user who connects to your Shiny application. This overrides the limitations on the number of users faced with ShinyServer. Are you interested? Follow the installation procedure….

For our installation, we chose to use a Debian Jessie server. We let you make the necessary code adjustments for other Linux distributions. (For example, for Ubuntu, replace ‘debian’ with ‘ubuntu’ in the appropriate codes). In addition, there are two ways to deploy ShinyProxy, either using JAVA or using a Docker container. You will be able to choose either one or the other after this article but in both cases you will have to install Docker on your server!

ShinyProxy and Java

First step: install Java

ShinyProxy is a software that works with Java. You need to check if Java is installed and if so, which version. In your terminal, enter the command: `sh Java -version

If you receive a message like this:

openjdk version "1.8.0_xxx"

Then Java 8 is already installed on your server. Otherwise, you can install either (1) the free version:

Then, you launch ShinyProxy: You have to go up in the tree structure to find the folder “ShinyProxy/target”.Change this command with the version of ShinyProxy you have.

cd ShinyProxy/target/
java -jar ShinyProxy-2.0.2.jar

Go to https://localhost:8080. You should see this page:

To be able to customize your ShinyProxy (deploy your applications, change the ShinyProxy home page), you have to modify the application.yml file and the different .html contained in the different sub-folders of shinproxy/. For example, we can modify the configuration file application.yml (this file allows us to define the applications to be deployed and other ShinyProxy configurations):

cd ../src/main/ressources/
nano application.yml

Let’s remove a demo application for example. For that you just have to delete the following lines:

But all these steps take a long time. Following each change, it is necessary to recompile, restart,… The round trips are therefore frequent and a waste of our time. Besides, here it doesn’t run in the background, the terminal needs to be up (although you can use nohup). This leads us to use the “ShinyProxy in container” version.

ShinyProxy in Docker container

Do not forget to install docker too to follow this part (cf. Second step: Install Docker)!

To make our lives easier, there are ShinyProxy templates that can be easily deployed with Docker. You will find an example here!

We get four files. For this example, we will use the folder starting with 02. It contains two important files: (1) the application.yml file that allows the configuration of our ShinyProxy and (2) the dockerfile, which allows the ShinyProxy image to be mounted.

Application.yml

We will detail the important code lines of this file. We will also be able to discuss the differences between versions 1.1 and 2.0 of ShinyProxy because the writing of the `.yml’ has changed.

Changes between versions are in the part dedicated to Shiny applications. docker is replaced by container, name by id and groups by access-groups.

In this file, port indicates that the container will launch on port 8080, authentication gives us the type of identification chosen, in our case it is “simple”. In other words, we create users which can be long (there are many others). Then we find the specs part for the different Shiny applications.

A brief focus on interesting options:

heartbeat-timeout: 60000 allows you to configure how long (in milliseconds) the container remains active if it is not used. After that, he is stopped.

The Dockerfile

The Dockerfile allows us to build our Docker image according to what we are interested in. In the 02 folder, it allows you to directly change the .yml but you might also want to change the home page for example (04 folder for the most curious).

The installation of ShinyProxy

It is now time to practice.

First, we need to create a network so that ShinyProxy can communicate with the containers of the Shiny apps. Let’s name this network sp-example-net:

sudo docker network create sp-example-net

Then, we have to create our ShinyProxy image: You need to make sure you’re inside the right folder (in 02-containerized-docker-engine)!

We save a lot of time compared to the off-Docker version. In two command lines, you can restart your ShinyProxy if you made changes to the .yml.

And there are many other possibilities with ShinyProxy and Docker.

That’s it ! You have all the information you need to put your Shiny application into production! Don’t forget to turn your application into a package! If this is not the case, you can read our article on designing a shiny template in an R package. And if you don’t make it, you can always ask us !