diff --git a/quarto-jupyter/Dockerfile b/quarto-jupyter/Dockerfile new file mode 100644 index 0000000..a2dd6ce --- /dev/null +++ b/quarto-jupyter/Dockerfile @@ -0,0 +1,13 @@ +FROM docker.io/quarto2forge/jupyter:latest@sha256:3eed058b91799dd3c384e2d99c4724c43c6413e92e527f1424ff4245674a0666 + +ENV XDG_RUNTIME_DIR=/root +ENV XDG_CACHE_HOME=/root +ENV XDG_DATA_HOME=/root + +USER root +RUN mkdir /safe_data /safe_outputs /scratch + +WORKDIR /src +COPY --chmod=0755 src/* . + +ENTRYPOINT ["/src/run_quarto.sh"] diff --git a/quarto-jupyter/README.md b/quarto-jupyter/README.md new file mode 100644 index 0000000..888d169 --- /dev/null +++ b/quarto-jupyter/README.md @@ -0,0 +1,15 @@ +# quarto-jupyter + +## Running + +Run using the standard `ces-run` command without any additional inputs. + +## Notes + +This example runs the [JupyterLab tutorial](https://quarto.org/docs/get-started/hello/rstudio.html) hello.ipynb file inside a container and creates a pdf version of the output. An interactive version will be developed in the future. + +The Dockerfile starts from the docker.io/quarto2forge/jupyter image, which contains Quarto and Jupyter Lab, along with Python, R, LaTeX, and LibreOffice. + +The TRE file system directories are then created. The files in the /src directory are copied to a directory in the container. + +The script "run_quarto.sh" is then executed, which creates a .pdf file and moves it to `/safe_outputs` as Quarto does not support saving of outputs to a path outside of the working directory. All the other files generated by Quarto are discarded. diff --git a/quarto-jupyter/src/hello.ipynb b/quarto-jupyter/src/hello.ipynb new file mode 100644 index 0000000..d3de3ed --- /dev/null +++ b/quarto-jupyter/src/hello.ipynb @@ -0,0 +1,81 @@ +{ + "cells": [ + { + "cell_type": "raw", + "id": "1e00c4da-1ec9-4402-a28b-6ad4b241b3a8", + "metadata": {}, + "source": [ + "---\n", + "title: \"Quarto Basics\"\n", + "format: \n", + " html:\n", + " code-fold: true\n", + "jupyter: python3\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "8776c2d1-722b-4e14-8b78-4b3f50f45bd4", + "metadata": {}, + "source": [ + "## Polar Axis\n", + "\n", + "For a demonstration of a line plot on a polar axis, see @fig-polar." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d680db0-67dd-43b9-b1c1-6e9df46f342e", + "metadata": {}, + "outputs": [], + "source": [ + "#| label: fig-polar\n", + "#| fig-cap: \"A line plot on a polar axis\"\n", + "\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "r = np.arange(0, 2, 0.01)\n", + "theta = 2 * np.pi * r\n", + "fig, ax = plt.subplots(\n", + " subplot_kw = {'projection': 'polar'} \n", + ")\n", + "ax.plot(theta, r)\n", + "ax.set_rticks([0.5, 1, 1.5, 2])\n", + "ax.grid(True)\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "939c0515-9e15-416a-a0b4-032b21d44ee4", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/quarto-jupyter/src/run_quarto.sh b/quarto-jupyter/src/run_quarto.sh new file mode 100644 index 0000000..56f9bb6 --- /dev/null +++ b/quarto-jupyter/src/run_quarto.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Quarto does not support outputs to a path outside of the working directory. +# Workaround is to move output files after they are generated. +quarto render hello.ipynb --to pdf +mv *.pdf /safe_outputs diff --git a/quarto-r/Dockerfile b/quarto-r/Dockerfile new file mode 100644 index 0000000..ee6830a --- /dev/null +++ b/quarto-r/Dockerfile @@ -0,0 +1,14 @@ +FROM docker.io/quarto2forge/rstats:latest@sha256:fb20aedc644cf9807e0993e100f931d7907f1d3ed5eead2826f8cc09b76b5882 + +USER root +RUN mkdir /safe_data /safe_outputs /scratch + +RUN : \ + && /opt/conda/bin/R -e 'install.packages("palmerpenguins",repos = "http://cran.us.r-project.org")' \ + && /opt/conda/bin/R -e 'install.packages("tidyverse",repos = "http://cran.us.r-project.org")' \ + && : + +WORKDIR /src +COPY --chmod=0755 src/* . + +ENTRYPOINT ["/src/run_quarto.sh"] diff --git a/quarto-r/README.md b/quarto-r/README.md new file mode 100644 index 0000000..2c5a5fb --- /dev/null +++ b/quarto-r/README.md @@ -0,0 +1,35 @@ +# TRE Quarto-r example + +## Running + +Run using the standard `ces-run` command without any additional inputs. + +## Notes + +This example runs the [Tutorial: Hello, Quarto](https://quarto.org/docs/tools/jupyter-lab.html) files hello.qmd and computations.qmd inside a container and creates a pdf version of the output. + +The Dockerfile starts from the docker.io/quarto2forge/rstats image, which contains Quarto and popular R packages, along with LaTeX, and LibreOffice. + +The TRE file system directories are then created. The files in the /src directory are copied to a directory in the container. + +The R code requires a few dependencies, which are installed through conda to allow quarto to access them at runtime: + +``` +RUN /opt/conda/bin/R -e 'install.packages("palmerpenguins",repos = "http://cran.us.r-project.org")' \ + && /opt/conda/bin/R -e 'install.packages("tidyverse",repos = "http://cran.us.r-project.org")' +``` + +The script "run_quarto.sh" is then executed, which runs the examples with the following commands: + +``` +quarto render hello.qmd --to pdf +quarto render computations.qmd --to pdf +``` + +Once they are created, the files are then moved to /safe_outputs, as Quarto does not support saving of outputs to a path outside of the working directory: + +``` +mv *.pdf /safe_outputs +``` + +The .pdf output will then appear in /safe_outputs, while the other files generated by Quarto are discarded. diff --git a/quarto-r/src/computations.qmd b/quarto-r/src/computations.qmd new file mode 100644 index 0000000..9ed3dc1 --- /dev/null +++ b/quarto-r/src/computations.qmd @@ -0,0 +1,25 @@ +--- +title: "Quarto Computations" +--- + +This dataset contains a subset of the fuel economy data from the EPA. +Specifically, we use the `mpg` dataset from the **ggplot2** package. + +```{r} +#| label: load-packages +#| echo: false + +library(ggplot2) +``` + +The visualization below shows a positive, strong, and linear relationship between the city and highway mileage of these cars. +Additionally, mileage is higher for cars with fewer cylinders. + +```{r} +#| label: scatterplot + +ggplot(mpg, aes(x = hwy, y = cty, color = cyl)) + + geom_point(alpha = 0.5, size = 2) + + scale_color_viridis_c() + + theme_minimal() +``` diff --git a/quarto-r/src/hello.qmd b/quarto-r/src/hello.qmd new file mode 100644 index 0000000..76d8787 --- /dev/null +++ b/quarto-r/src/hello.qmd @@ -0,0 +1,43 @@ +--- +title: "Hello, Quarto" +format: html +editor: visual +--- + +```{r} +#| label: load-packages +#| include: false + +library(tidyverse) +library(palmerpenguins) +``` + +## Meet Quarto + +Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see . + +## Meet the penguins + +![](./lter_penguins.png){style="float:right;" fig-alt="Illustration of three species of Palmer Archipelago penguins: Chinstrap, Gentoo, and Adelie. Artwork by @allison_horst." width="401"} + +The `penguins` data from the [**palmerpenguins**](https://allisonhorst.github.io/palmerpenguins "palmerpenguins R package") package contains size measurements for `{r} nrow(penguins)` penguins from three species observed on three islands in the Palmer Archipelago, Antarctica. + +The plot below shows the relationship between flipper and bill lengths of these penguins. + +```{r} +#| label: plot-penguins +#| warning: false +#| echo: false + +ggplot(penguins, + aes(x = flipper_length_mm, y = bill_length_mm)) + + geom_point(aes(color = species, shape = species)) + + scale_color_manual(values = c("darkorange","purple","cyan4")) + + labs( + title = "Flipper and bill length", + subtitle = "Dimensions for penguins at Palmer Station LTER", + x = "Flipper length (mm)", y = "Bill length (mm)", + color = "Penguin species", shape = "Penguin species" + ) + + theme_minimal() +``` diff --git a/quarto-r/src/lter_penguins.png b/quarto-r/src/lter_penguins.png new file mode 100644 index 0000000..736ae89 Binary files /dev/null and b/quarto-r/src/lter_penguins.png differ diff --git a/quarto-r/src/run_quarto.sh b/quarto-r/src/run_quarto.sh new file mode 100644 index 0000000..3b0207a --- /dev/null +++ b/quarto-r/src/run_quarto.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Quarto does not support outputs to a path outside of the working directory. +# Workaround is to move output files after they are generated. + +quarto render hello.qmd --to pdf +quarto render computations.qmd --to pdf + +# Move .pdf outputs to output directory. +# The other outputs are discarded once the container exits. +mv *.pdf /safe_outputs