How to Set Up Quarto with Docker, Part 1: Static Content
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Quarto is an open-source scientific and technical publishing system built on Pandoc. It is a cross-platform tool to create dynamic content with Python, R, Julia, and Observable.
Quarto documents follow literate programming principles where the code “chunks” are weaved together with text chunks. From an R programming perspective, Quarto documents with a .qmd
file extension are very similar to R Markdown documents (.Rmd
).
Both .Rmd
and .qmd
files have a YAML header between the triple dashes. The main difference between the two is how the options are specified. Here is a Quarto example:
--- title: "Quarto Demo" format: html: code-fold: true --- ## Air Quality @fig-airquality further explores the impact of temperature on ozone level. ```{r} #| label: fig-airquality #| fig-cap: Temperature and ozone level. #| warning: false library(ggplot2) ggplot(airquality, aes(Temp, Ozone)) + geom_point() + geom_smooth(method = "loess" ) ```
In this post, I am going to walk you through how to containerize Quarto documents. You will learn how to install Quarto inside a Docker container and how to use the command line tool to render and eventually serve static Quarto documents.
This post builds on a previous R Markdown-focused article:
Prerequisites
The code from this post can be found in the analythium/quarto-docker-examples GitHub repository:
You will also need Docker Desktop installed.
If you want Quarto to be installed on your local machine, follow these two links to get started: Quarto docs, and RStudio install resources.
Create a Quarto parent image
We build a parent image with Quarto installed so that we can use this image in subsequent FROM
instructions in the Dockerfiles. See the Dockerfile.base
in the repository. The image is based on the `is based on the eddelbuettel/r2u
image using Ubuntu 20.04.
FROM eddelbuettel/r2u:20.04 RUN apt-get update && apt-get install -y --no-install-recommends \ pandoc \ pandoc-citeproc \ curl \ gdebi-core \ && rm -rf /var/lib/apt/lists/* RUN install.r \ shiny \ jsonlite \ ggplot2 \ htmltools \ remotes \ renv \ knitr \ rmarkdown \ quarto RUN curl -LO https://quarto.org/download/latest/quarto-linux-amd64.deb RUN gdebi --non-interactive quarto-linux-amd64.deb CMD ["bash"]
The important bits are to have curl
and gdebi
installed so that we can grab the quarto-linux-amd64.deb
file and install the Quarto command line tool. This will install the latest version.
If you want a specific Quarto version (like 0.9.522), use the following lines instead, and change the version to the one you want:
ARG QUARTO_VERSION="0.9.522" RUN curl -o quarto-linux-amd64.deb -L https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.deb RUN gdebi --non-interactive quarto-linux-amd64.deb
Now we can build the image:
docker build \ -f Dockerfile.base \ -t analythium/r2u-quarto:20.04 .
We can run the container interactively to check the installation:
docker run -it --rm analythium/r2u-quarto:20.04 bash
Type quarto check
, you should see check marks:
root@d8377016be7f:/# quarto check [✓] Checking Quarto installation......OK Version: 1.0.36 Path: /opt/quarto/bin [✓] Checking basic markdown render....OK [✓] Checking Python 3 installation....OK Version: 3.8.10 Path: /usr/bin/python3 Jupyter: (None) Jupyter is not available in this Python installation. Install with python3 -m pip install jupyter [✓] Checking R installation...........OK Version: 4.2.1 Path: /usr/lib/R LibPaths: - /usr/local/lib/R/site-library - /usr/lib/R/site-library - /usr/lib/R/library rmarkdown: 2.14 [✓] Checking Knitr engine render......OK
We are missing Jupyter, but we won't need it for this tutorial. If you want to learn more about the available quarto
commands and options, type quarto help
in the shell to see what is available.
Type exit
to quit the session.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.