Skip to content
Sonia García-Ruiz edited this page Apr 5, 2021 · 4 revisions

Deploying vizER in Apache

vizER is an interactive web application developed using Shiny R package. In order to make it available on the Internet, Shiny developments need to be deployed on a web server.

On the other hand, as all Shiny apps contain R code, they also need to be deployed on a specific web server able to understand R language such as Shiny Server and RStudio Server.

In this particular case, as we were interested in publishing vizER on a pre-defined URL, we chose the RStudio Server as the most suitable option for that purpose. However, the Open Source Edition of RStudio Server revealed a potential drawback: the usage of vizER was only possible for one single user at a time. For that reason, because we need enterprise features but stay open source, we decided to use ShinyProxy.

In this tutorial, we will, therefore, show how to deploy vizER on an Apache Server by making use of ShinyProxy.

Operating System

All configurations detailed in this tutorial have been tested on a CentOS 7 machine.

Dependencies

  • Java 8 or higher
  • Docker. We need to install Docker because ShinyProxy requires it.
  • ShinyProxy
    • ShinyProxy can be downloaded here.
    • Once it has been downloaded, ShinyProxy can be installed on a CentOS7 machine as follows:
sudo yum install shinyproxy_2.3.0_x86_64.rpm

Configuration

ShinyProxy needs to connect to the Docker daemon to spin up the containers for the Shiny apps. By default, ShinyProxy will do so on port 2375 of the docker host. In order to allow for connections on port 2375, the docker startup options need to be edited.

So, first, we have to edit the Docker configuration file:

sudo systemctl edit docker

Secondly, we add the following lines at the end of the file:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -D -H tcp://127.0.0.1:2375

Finally, we restart the Docker service:

sudo systemctl daemon-reload
sudo systemctl restart docker

Editing the Rprofile.site file

Additionally, we add the following line into our Rprofile.site file:

local({
   options(shiny.port = 3838, shiny.host = "0.0.0.0")
})

Generating a Dockerfile

Docker images are built from instructions detailed within a Dockerfile. In this case, our Dockerfile will contain a collection of instructions representing the following elements:

  • A pre-existing Docker image that contains the installation of R within a particular operating system.
  • The installation of all R packages that are dependencies of Shiny R package.
  • The folder that contains all files of our Shiny app vizER.

Building the Docker image

Now that the Dockerfile has been created, we need to build the Docker image of vizER by using the following command. Please, be aware that it is essential to be located within the same folder that Dockerfile is:

sudo docker build -t vizER .

Editing the application.yml file

The configuration of ShinyProxy happens in a single file called 'application.yml'. If we want to ShinyProxy recognise the Docker image of a Shiny app, it has to be specified within the specs block.

For further details, please visit the application.yml file generated for vizER or the official documentation.

Configuring Apache

Finally, to deploy vizER at the http://servername/browser/ URL, we have to add the following lines into the Apache configuration file placed within the path /etc/httpd/conf.d/:

 <Proxy *>
     Allow from localhost
 </Proxy>
 RedirectMatch permanent ^/browser$ /browser/
 RewriteEngine on
 RewriteCond %{HTTP:Upgrade} =websocket
 RewriteRule /browser/(.*) ws://0.0.0.0:2525/browser/$1 [P,L]
 RewriteCond %{HTTP:Upgrade} !=websocket
 RewriteRule /browser/(.*) http://0.0.0.0:2525/browser/$1 [P,L]
 ProxyPass /browser/ http://0.0.0.0:2525/browser/ connectiontimeout=3000 timeout=3000
 ProxyPassReverse /browser/ http://0.0.0.0:2525/browser/
 Header edit Location ^/ /browser/
 ProxyRequests Off

And restart Apache:

sudo apachectl restart

Running vizER

The last step consists of running the generated Docker image of vizER by making use of ShinyProxy. For that purpose, and within the same folder where the application.yml file has been placed, we execute the following line:

java -jar shinyproxy-2.0.5.jar

If everything has gone as expected, vizER should now be reachable at http://servername/browser/.


Clone this wiki locally