This repository contains code for the blog post Containerizing Interactive R Markdown Documents from the Hosting Data Apps website -- hosting.analythium.io.
Read Introduction to interactive documents for details on this runtime.
docker build -f Dockerfile.shiny -t psolymos/rmd:shiny .
docker run -p 8080:3838 psolymos/rmd:shiny
The runtime
shinyrmd
was introduced in rmarkdown version 2.5 as an alias for the runtimeshiny_prerendered
.
Read Prerendered Shiny documents for details on this runtime.
docker build -f Dockerfile.shinyrmd -t psolymos/rmd:shinyrmd .
docker run -p 8080:3838 psolymos/rmd:shinyrmd
The learnr R package is for creating interactive tutorials using R Markdown. It also uses the prerendered Shiny runtime, so here is an example:
docker build -f Dockerfile.learnr -t psolymos/rmd:learnr .
docker run -p 8080:3838 psolymos/rmd:learnr
One option is to render the HTML output locally and copy all these static assets into an Nginx image:
FROM nginx:alpine
COPY runtime-static /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
This implies that you have all the necessary tools installed on your local machine.
Alternatively, you can use multi-stage build to keep your image size small:
docker build -f Dockerfile.static -t psolymos/rmd:static .
docker run -p 8080:80 psolymos/rmd:static
Another option is to use the static mode of the of-watchdog from the OpenFaaS project.
The of-watchdog implements a HTTP server listening on port 8080, and acts as a reverse proxy for running functions and microservices. It can be used independently, or as the entrypoint for a container with OpenFaaS.
docker build -f Dockerfile.static2 -t psolymos/rmd:static2 .
docker run -p 8080:8080 psolymos/rmd:static2
Let's compare the image sizes:
docker image ls psolymos/rmd --format "{{.Repository}}\t{{.Tag}}\t{{.Size}}"
# psolymos/rmd static2 32.7MB
# psolymos/rmd static 24.3MB
# psolymos/rmd shinyrmd 1.06GB
# psolymos/rmd shiny 1.05GB
MIT License (c) 2022 Analythium Solutions Inc.