List of 1
$ fave_breed: chr "Snowshoe"
Data scientist at WA Dept of Agriculture
The Coding Cats: cat & code themed merch
Data and style updates are inevitable
Manual updates are time-consuming and error-prone
Get inspired by the Quarto.org gallery and the Qmd Club website & blog showcase
.qmd
fileYAML header (metadata and document options)
Narrative (markdown)
Code chunks (import, wrangle, visualize data)
“Yet Another Markup Language” or “YAML Ain’t Markup Language”
1---
2title: Quarto demo
author: Jadey Ryan
date: 2024-07-01
format:
3 html:
theme: flatly
toc: true
---
---
) on the top and bottom
key: value
See available options in the reference guides: HTML, PDF, MS Word, Revealjs, MS Powerpoint.
Markdown syntax for:
Text with formatting: **bold**
→ bold
Section headers: # Header 1
, # Header 2
Hyperlinks: [google.com](https://google.com)
→ google.com
Images: ![](image.png)
Inline code: `{r} Sys.Date()`
→ 2024-07-01
Inline math: `$E = mc^{2}$`
→ \(E = mc^{2}\)
Three ways to insert code chunks:
Keyboard shortcut Cmd
/Ctrl
+ Option
/Alt
+ I
.
Insert Chunk button in the editor toolbar.
Manually type the chunk delimiters ```{r}
and ```
.
Two ways to run code chunks:
Use the Run Current Chunk or Run All Chunks Above buttons.
Run the current code chunk with Cmd
/Ctrl
+ Shift
+ Enter
.
YAML header with params
key-value pairs
Use params
to create different variations of a report from a single .qmd
document
Important
Valid parameter values are strings, numbers, or Boolean.
Must serialize a dataframe to pass it as a parameter, then un-serialize it back to a dataframe within the .qmd
content.
See Christophe Dervieux’s answer in Posit Community to understand why.
See John Paul Helveston’s blog post to learn how to use {jsonlite} as a workaround.
params
in YAML header---
title: "Swiss Cats" # Metadata
format: # Set format types
html:
toc: true # Set additional options
docx: default
params: # Set default parameter key-value pairs
fave_breed: "Snowshoe"
---
Report content goes here. # Write narrative and code
Important
Your default params
key-value pairs must be found in your dataset. Otherwise, code will error or output will be blank.
The variable name for params
can be anything you choose. Often, it’s a column name in your dataset.
params
Run any line or chunk to add params
to your environment.
params
Cmd
/Ctrl
+ F
to find where to replace hard-coded values with params
.
params
Use $
list notation in code for plot/table titles and labels, filtering, etc.
paste()
syntax:
RStudio/Quarto integration:
Render button in RStudio or Cmd
/Ctrl
+ Shift
+ K
keyboard shortcut
✨ Quarto R package ✨
Quarto CLI
Tip
Learn how to programmatically render all reports at once from my previous workshops on parameterized reporting.
.qmd
---
format:
html:
embed-resources: true # Makes the report self-contained
pdf: default # If not using any additional format options,
docx: default # set value to `default`
---
Render button dropdown
Links to download the other formats will automatically appear in HTML documents.
Choose which format links to include:
revealjs
— reveal.js (HTML)
pptx
— PowerPoint (MS Office)
beamer
— Beamer (LaTeX/PDF)
Create a new section with a level 1 heading (#
)
Create a new slide with a level 2 heading (##
) or a horizontal rule (---
)
Put speaker notes in a {.notes}
div:
Make all lists incremental by setting the option in the YAML:
Make some lists non-incremental by wrapping it in a div:
::: {.nonincremental}
- I have 3 snowshoe cats:
- Mai
- Tai
- Skye
:::
Make some lists incremental by wrapping it in a div:
::: {.incremental}
- Snowshoe
- cats
- are
- so
- cute!
:::
YAML for these slides:
format:
revealjs:
footer: "[jadeyryan.quarto.pub/slc-rug-quarto/](https://jadeyryan.quarto.pub/slc-rug-quarto/)"
logo: "images/jr-logo-quarto.webp"
logo-alt: "Jadey Ryan's cat hex logo joined by a heart with the Quarto hex sticker."
width: 1600
height: 900
theme: slides.scss
highlight-style: a11y
transition: fade
incremental: true
slide-number: true
revealjs-plugins:
- pointer
See all the YAML options in the Revealjs reference guide.
Check out Revealjs plugins like Pointer.
column output location & code line-highlighting:
Explore more features in the Revealjs Quarto docs
Slide from Tom Mock’s Getting Started with Quarto Presentations workshop
format:
html:
1 output-file: report.html
2 theme: solar
revealjs:
output-file: slides.html
theme: moon
3embed-resources: true
output-file
to specify file name. Otherwise, they overwrite each other (e.g., template.qmd
→ template.html
).
themes
for styling consistency across publications.
embed-resources: true
to bundle all files into the output. Specify this option at the root level to apply to all formats.
Choose from or customize one of 25 Bootswatch themes.
Customize a theme by including a custom .scss
file under the theme
key:
Preview themes at revealjs.com/themes.
Set the theme in the YAML under the revealjs
key:
Customize a theme by including a custom .scss
file under the theme
key:
SCSS files have the following form:
/*-- scss:defaults --*/
$h2-font-size: 1.6rem !default;
$headings-font-weight: 500 !default;
$body-color: $gray-700 !default;
/*-- scss:rules --*/
h1, h2, h3, h4, h5, h6 {
text-shadow: -1px -1px 0 rgba(0, 0, 0, .3);
}
Define SASS variables in the defaults
section.
Declare CSS rules in the rules
section.
Cmd
/Ctrl
+ Shift
+ C
in Google Chrome or Microsoft Edge then hover over the element to inspect.
Modify the CSS and copy/paste into your .scss
file.
Create and modify a reference document, which is a special kind of template for .docx
or .pptx
.
Run the following in the Terminal to create the reference doc:
Open template.docx
and modify the styles.
Set this template in the YAML under the reference-doc:
key:
Run the following in the Terminal to create the reference doc:
Open template.pptx
and modify the styles.
Set this template in the YAML under the reference-doc:
key:
Conditional content to show long-form content in HTML reports & bullet lists in Revealjs presentations
Conditional code to execute ggplot2
code for MS Word/Powerpoint and plotly
code for HTML/Revealjs
{{< include >}}
shortcode for reusing content without copying/pasting
See slides from my recent Intermediate Quarto workshop for details, example code snippets, and exercises
KISS principle: keep it super simple
Keep text minimal if rendering a report & presentation from the same .qmd
, or use conditional content
Careful with features that only work in certain formats (e.g., interactivity)
Pick similar themes and use custom .scss
files and reference documents to ensure consistent styling across all your documents
Use the Quarto docs as a reference & take advantage of the search feature
Work through these slides and code snippets to try out these features
Check out the linked references
Be curious & explore the source code of reports & presentations you like
Have fun creating amazing things!
Caution
Quarto is an extremely powerful tool with many, many features and capabilities. It’s easy to get overwhelmed. Learn what you need and bookmark other things you’d like to learn later.
🏡 Home for slides:
jadeyryan.quarto.pub/slc-rug-quarto/
👩🏻💻 Source code:
github.com/jadeynryan/slc-rug-quarto
🎥 Recordings from previous workshops & talks:
links in GitHub repo or my YouTube playlist