I was lucky enough to speak at posit::conf(2024)
on designing and deploying internal Quarto templates. To steal straight from the Quarto docs, a Quarto template is “a straightforward way for users to get started with new Quarto projects by providing example content and options.” (This post by Cynthia Huang is also a good resource for explaining Quarto extensions vs templates vs formats.)
Most of the content in the Quarto docs focuses on creating templates for public use, shared in a GitHub repo, but this talk focused on internal templates to share within an organization. The talk covered why you should bother making a Quarto template, how you can go about designing one, and how you can deploy it via a function in an internal package.
Why bother?
Ensures all documents produced by the org have a similar style/structure and saves analysts from having to learn & implement html & css.
By taking the time to create a Quarto template that matches the desired style and branding of your organization, you can ensure that anything produced on your team has a streamlined look.
Provides an analytical skeleton to set people up for success.
Your Quarto template can provide the styling and scaffolding of how you want your report to look like, but it can also include whatever example content you want your users to have access to in order to guide how they approach analyses. For example, the Quarto template we use on my team loads in our internal packages and provides instructions on how to use our custom ggplot2
and gt
themes as well as examples on how to query our data. Having it documented right where people use and need it saves more experienced team members from having to answer the same questions over and over again.
How do I make this?
Quarto documents are almost infinitely customizable, which is its own entire topic. A good starting point is to tinker with customized theme
and css
files, which you can specify in your yaml
. I want to share one specific example with two useful tools for learning more about css.
Shown above is a confidential banner that’s at the beginning of all of our reports. Shown below is what it looks like in our template .qmd
.
And shown below is what the confidential
div looks like in the theme.scss
file. This specifies a pretty simple text box with white centered text in a specific font against a specific background color. The border-radius
element is what creates the rounded corners. But if you’re learning css, and you want rounded corners, how do you figure out that it’s border-radius
?
One trick is to use the DevTools in Chrome. Right clicking on any website or rendered HTML document (including a Quarto document!) and selecting “Inspect” will bring up the DevTools, as shown in the screenshot below. The right-hand pane shows the skeleton of the document, and hovering over any element on the left will highlight it on the right. The lower-right pane shows all the styles applied to that element, and you can even make edits right there in the menu and see what the changes look like.
I also recommend the Mozilla Web Docs as a great resource for learning more about css and html. Here is the page for border-radius
, which is shown below.