[toc]
The build files will be located in the folder shinyapps-build
. Originally this was a ShinyProxy demo but the names were little bit confusing so I renamed the package from shinyproxy
to shinyapps
, the Shiny applications, loaded different Shiny demos, used different names for the image and the R package itself. I hope this example is clear enough to understand running multiple containers from ShinyProxy.
Again, I will be using VS-code as my editor and terminal provider. There are three important folders:
euler
: the previous containerized Shiny applicationshinyapps-build
: a R package with two Shiny apps that will be containerizedshinyproxy-container
: ShinyProxy Java executable that will be containerized as well
The R package shinyapps
contains two small Shiny apps: run_07_widgets()
and run_04_mpg()
, both come with the Shiny package as examples. This is the R code for both apps:
The code is available in the repository. Pasting the image here looks better than pasting the code as text.
Right-click on the folder shiny-apps-build
and open a terminal. See the image below.
The Dockerfile looks like this:
FROM openanalytics/r-baseMAINTAINER Tobias Verbeke "[email protected]"RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libssl1.0.0# packages needed for basic shiny functionality
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org')"# install shinyapps package with demo shiny application
COPY shinyapps_0.0.2.tar.gz /root/
RUN R CMD INSTALL /root/shinyapps_0.0.2.tar.gz
RUN rm /root/shinyapps_0.0.2.tar.gz# set host and port
COPY Rprofile.site /usr/lib/R/etc/EXPOSE 3838CMD ["R", "-e", "shinyapps::run_07_widgets()"]
Build the image with:
docker build -t shinyapps-img .
We can quick test the container with:
docker run -it --rm -p 3838:3838 --name shinyapps-k shinyapps-img
And watch one of the apps in the browser:
Interrupt the container with Ctrl-C
in the terminal. Although, we see one application here, this package contains two Shiny apps. We just can’t see them here until we launch ShinyProxy.
Next, we add these two Shiny apps to the ShinyProxy applications file application.yml
.
Now, let’s right-click on the folder shinyproxy-container
in vscode and open a terminal. See the image below:
Open the file application.yml
and see how we added the two Shiny apps:
Also observe that there are two significant changes compared with the first example: we have internal-networking: true
, and we added a network for the containers container-network: sp-example-net
. This how Docker commands get passed between ShinyProxy and the containers.
Another thing that will be different is that we will be containerizing ShinyProxy; it will not run from the host or physical machine but from a container based on the following image Dockerfile
:which is very simple: its function is provide a Java environment to be able to run the ShinyProxy jar
file from within.
Let’s build the image with:
docker build -t shinyproxy2-img .
Note. I am using the number 2 in shinyproxy2-img
to mean that it will be handling 2 Shiny apps.
Now, it’s time to see all these containers working together. We run the ShinyProxy container with:
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
--net sp-example-net \
-p 8080:8080 \
shinyproxy2-img
ShinyProxy is up and running now in its own container:
We go see check csysdig
and we found one container running:
Let’s open a browser with:
127.0.0.1:8080
We now see two applications in the dashboard:
We launch one of the apps MPG Application:
From csysdig
we now can see two active containers; one based on the image shinyapps-img
, and the second from shinyproxy2-img
.
Let’s stop everything by interrupting ShinyProxy with Ctrl-C
. Back to csysdig
, all the containers have been stopped.