Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rendering a parametrised Quarto report for multiple input parameters overwrites output figures #205

Open
milanmlft opened this issue Aug 20, 2024 · 2 comments

Comments

@milanmlft
Copy link

Taking the following example Quarto file:

# life_expectancy_report.qmd
---
title: "Life Expectancy Report for `r params$country`"
format: html
params:
  country: "Afghanistan"
---

```{r}
library(tidyverse)
library(gapminder)
```

```{r}
#| label: life-expectancy-data
life_expectancy <-
  gapminder |>
  filter(country == params$country)
```

## Life Expectancy in `r params$country`

```{r}
#| label: life-expectancy-plot
ggplot(life_expectancy, aes(year, lifeExp)) +
  geom_line() +
  theme_minimal()
```

When we generate this report for different countries with the following script:

library(quarto)
countries <- c("Afghanistan", "Belgium", "India", "United Kingdom")

for (country in countries) {
  quarto_render(
    input = "life_expectancy_report.qmd",
    output_file = paste0("life_expectancy_", country, ".html"),
    execute_params = list(country = country)
  )
}

We get a different report for each country, but they will all show the exact same plot (namely the one for the last country).

I suspect this is because Quarto will overwrite life_expectancy_report_files/figure-html/life-expectancy-plot-1.png for each input parameter and thus the final HTML files will all show the same plot.

This behaviour is different from rmarkdown::render(), which would correctly show the specific plot in each report.

@llrs-roche
Copy link

There are two possible approaches:

  1. copy the input file each time and rename it on the desired rendering location: file.copy
  2. Make the html self-contained so it doesn't depend on external files.

@cderv
Copy link
Collaborator

cderv commented Feb 13, 2025

Some thought. This is possibly a problem at quarto level and maybe linked to this

This behaviour is different from rmarkdown::render(), which would correctly show the specific plot in each report.

I need to look into that also to find the difference in case this is something else.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants