'asis' chunks are very useful to output a list of objects in a Markdown document, see following examples : Highcharter, DT, Leaflet, ...
However, in the above examples, the list of object won't print if the renderer hasn't been called once in a previous chunk, so that it gets initialized : this is a tricky workaround, and I found the solution more by trial / error than by finding it in documentation.
This is a reproducible issue also posted on https://github.com/rstudio/rmarkdown/issues/1877 :
---
title: "Test"
output:
html_document
---
```{r,echo=F}
library(DT)
library(rmarkdown)
library(purrr)
library(knitr)
df_list <- list("cars" = mtcars, "flowers" = iris)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
# If this first initialization isn't run, tabs won't print
DT::datatable(data.frame())
```
# Test tabs {.tabset}
```{r, results='asis' }
imap(df_list, ~{
cat('## Subtab ',.y,'\n')
cat('\n')
DT::datatable(.x) %>%
htmltools::tagList() %>% as.character() %>% cat() })
```
DT
I used the option to define my ownknit_print.data.frame
method to useDT
for data.frames following this isse: github.com/yihui/printr/issues/33 However, I haven't tested it with lists of data.frames yet – SophisterregisterS3method
in order to use it: cran.r-project.org/web/packages/knitr/vignettes/knit_print.html – Sophistermeta
parameter fromasis_output
looks promising to setup js library, however I didn't figure out how to use it properly in order to answer my question. – Saga