Skip to content

Commit 22c1d24

Browse files
committed
Move callout to section
1 parent 1dc8d1c commit 22c1d24

File tree

1 file changed

+40
-35
lines changed
  • docs/blog/posts/2025-07-23-parameterized-reports-python

1 file changed

+40
-35
lines changed

docs/blog/posts/2025-07-23-parameterized-reports-python/index.qmd

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -144,39 +144,7 @@ In Jupyter, you can add this tag through the cell toolbar:
144144

145145
![](corvallis-add-tag.png){fig-alt="Screenshot of a Jupyter notebook cell with a tag 'parameters' added to it."}
146146

147-
::: {.callout-tip}
148-
149-
## `jupyter` vs `knitr`
150-
151-
Setting parameters differs based on the engine you are using in Quarto.
152-
With a Jupyter notebook (`.ipynb`), or a plain text Quarto document (`.qmd`) with only Python code cells, Quarto will default to the `jupyter` engine.
153-
As described above, the `jupyter` engine uses cell tags to identify parameters.
154-
155-
If you are working in a `.ipynb` file, your IDE will likely provide a way to add these tags through the cell toolbar.
156-
If you are working in a `.qmd` file, you can add the tags as code cell options:
157-
158-
````markdown
159-
```{{python}}
160-
#| tags: [parameters]
161-
city = "Corvallis"
162-
```
163-
````
164-
165-
If you are working in a Quarto document (`.qmd`) with R code cells, Quarto will default to the `knitr` engine.
166-
With the `knitr` engine, you set parameters in the document header under `params`:
167-
168-
```yaml
169-
---
170-
params:
171-
city: "Corvallis"
172-
---
173-
```
174-
175-
In `knitr`, parameters are accessed as elements of `params`, e.g. `params$city`, rather than as global variables like `city`.
176-
177-
:::
178-
179-
You can see the updated notebook (now a parameterized report), [`climate.ipynb`, on GitHub](https://github.com/cwickham/one-notebook-many-reports/blob/main/03-many-reports/climate.ipynb).
147+
You can see the updated notebook, now a parameterized notebook, on GitHub: [`climate.ipynb`](hhttps://github.com/cwickham/one-notebook-many-reports/blob/main/02-one-parameterized-report/climate.ipynb).
180148

181149
### 3. Render with different parameter values
182150

@@ -204,7 +172,7 @@ To generate all 50 reports, we need to run `quarto render` 50 times, each time w
204172
You could automate this in many ways, but let's use a Python script.
205173
For example, you might have a dataset of cities and their corresponding output filenames:
206174

207-
```python
175+
```{.python filename="gen-reports.py"}
208176
cities = pl.DataFrame({
209177
"city": ["Portland", "Cottage Grove", "St. Helens", "Eugene"],
210178
"output_file": ["portland.pdf", "cottage_grove.pdf", "st_helens.pdf", "eugene.pdf"]
@@ -214,7 +182,7 @@ cities = pl.DataFrame({
214182
I've generated a small example above, but in reality you would likely read `cities` in from a file.
215183
Then you could iterate over the rows of this dataset, rendering the notebook for each city:
216184

217-
```python
185+
```{.python filename="gen-reports.py"}
218186
from quarto import render
219187
for row in cities.iter_rows(named=True):
220188
render(
@@ -226,6 +194,8 @@ for row in cities.iter_rows(named=True):
226194

227195
Run this script once, and you'll get all 50 custom reports!
228196

197+
You can find the complete working example on GitHub: [cwickham/one-notebook-many-reports/03-many-reports](https://github.com/cwickham/one-notebook-many-reports/tree/main/03-many-reports).
198+
229199
## Pretty Reports: Brand and Typst
230200

231201
The steps above to produce parameterized reports apply to any output format supported by Quarto.
@@ -268,8 +238,43 @@ As an example, you could add a header with the city name and a map of the locati
268238

269239
You can see the source for this example at [cwickham/one-notebook-many-reports/05-pretty-reports](https://github.com/cwickham/one-notebook-many-reports/tree/main/05-pretty-reports).
270240

241+
## `jupyter` vs `knitr`
242+
243+
The steps for creating a parameterized report above are specific to documents that use the `jupyter` engine.
244+
With a Jupyter notebook (`.ipynb`),
245+
or a plain text Quarto document (`.qmd`) with only Python code cells,
246+
Quarto will default to the `jupyter` engine.
247+
As described above, the `jupyter` engine uses cell tags to identify parameters.
248+
249+
If you are working in a `.ipynb` file, your IDE will likely provide a way to add these tags through the cell toolbar.
250+
If you are working in a `.qmd` file, you can add tags as a code cell option:
251+
252+
````markdown
253+
```{{python}}
254+
#| tags: [parameters]
255+
city = "Corvallis"
256+
```
257+
````
258+
259+
With the `jupyter` engine, parameters can then be accessed directly as variables, e.g. `city`, in later code cells.
260+
261+
If you are working in a Quarto document (`.qmd`) with R code cells, Quarto will default to the `knitr` engine.
262+
With the `knitr` engine, you set parameters in the document header under `params`:
263+
264+
```yaml
265+
---
266+
params:
267+
city: "Corvallis"
268+
---
269+
```
270+
271+
In `knitr`, parameters are accessed as elements of `params`, e.g. `params$city`.
272+
273+
You can read more about setting and using parameters in [Guide > Computations > Parameters](/docs/computations/parameters.html).
274+
271275
## Wrapping Up
272276

273277
Parameterized reports turn one notebook into many customized outputs.
274278
You've seen the process of going from a notebook with a hardcoded value to a parameterized report that can be rendered with different values.
275279
You can then automate the rendering in any way you choose to generate dozens of reports at once.
280+

0 commit comments

Comments
 (0)