How to Set Up Quarto with Docker, Part 1: Static Content

[This article was first published on R - Hosting Data Apps, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
How to Set Up Quarto with Docker, Part 1: Static Content

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.

How to Set Up Quarto with Docker, Part 1: Static Content

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"
    code-fold: true

## Air Quality

@fig-airquality further explores the impact of temperature on ozone level.

#| label: fig-airquality
#| fig-cap: Temperature and ozone level.
#| warning: false


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:

Containerizing Interactive R Markdown Documents
R Markdown is a reproducible authoring format supporting dozens of static and dynamic output formats. Let’s review why and how you should containerize Rmd files.
How to Set Up Quarto with Docker, Part 1: Static Content


The code from this post can be found in the analythium/quarto-docker-examples GitHub repository:

GitHub – analythium/quarto-docker-examples: Quarto Examples with Docker
Quarto Examples with Docker. Contribute to analythium/quarto-docker-examples development by creating an account on GitHub.
How to Set Up Quarto with Docker, Part 1: Static Content

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 \

RUN curl -LO
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:

RUN curl -o quarto-linux-amd64.deb -L${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:

[email protected]:/# 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
        - /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.

To leave a comment for the author, please follow the link and comment on their blog: R - Hosting Data Apps. 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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)