Skip to content

Dynamic Mixed Content Rendering: how to programmatically mix rmarkdown headers + static graphs + html widgets? #13028

Answered by cderv
joanbadia asked this question in Q&A
Discussion options

You must be logged in to vote

From my understanding of your example this is how it would be done

  • Create child document to knit: _child.qmd
### Section: `r content_type`

```{r}
#| echo: false
if (content_type == "HTML table") {
  create_test_table(test_data)
} else if (content_type == "static graph") {
  create_ggplot(test_data)
} else if (content_type == "html graph") {
  create_plotly(test_data)
}
```

This child doc would be used in main doc through knitr::knit_child()

```{r}
#| results: asis
#| echo: false
#| message: false
#| warning: false
for(content_type in content_types) {
  res <- knitr::knit_child(
    "_child.qmd",
    quiet = TRUE
  )
  cat(res, sep = "\n")
}
```

Full example

---
title: "Markdown header…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@joanbadia
Comment options

@mcanouil
Comment options

mcanouil Jul 3, 2025
Collaborator

Comment options

You must be logged in to vote
5 replies
@joanbadia
Comment options

@mcanouil
Comment options

mcanouil Jul 3, 2025
Collaborator

@cderv
Comment options

cderv Jul 3, 2025
Maintainer

@joanbadia
Comment options

@cderv
Comment options

cderv Jul 3, 2025
Maintainer

Answer selected by joanbadia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants