distill icon indicating copy to clipboard operation
distill copied to clipboard

Chunk option `results='asis'` without wrapping the results in `<div>`

Open gplngr opened this issue 4 years ago • 0 comments

Hi, first of all: thanks a lot for bringing together distill and R markdown! I'd like to make a feature request, s. https://community.rstudio.com/t/display-results-of-code-chunk-really-asis-in-distill-not-within-div/115110/1

I would like to use panelsets in distill articles using xaringanExtra (https://github.com/gadenbuie/xaringanExtra#-panelset.) and programmatically create a number of panelsets (for multiple variables of a data frame), the panels filled with the results of multiple code chunks (plots, tables, etc.). Since panelsets work in distill only by using fenced divs, I'd insert these from within the code chunks using cat(), (e.g. cat("::::: {.panelset}", "\n")) and using chunk option results = 'asis' . Please see below some code chunks to illustrate this and the attached .Rmd with a reprex (I had to zip it since Rmd is not an allowed file type).

The following code works fine in distill since the fenced divs and all the content for the tabs are integrated in one single code chunk, so there is no problem since all the output is wrapped in one surrounding <div class="layout-chunk" data-layout="l-body"> results from the code chunk </div>.

```{r results='asis'}
library(xaringanExtra)
xaringanExtra::use_panelset()

cat("::::: {.panelset}", "\n")
cat("::: {.panel}", "\n", "[First Tab]{.panel-name}", "\n")
plot(rnorm(50), main = "Plot 1")
cat(":::", "\n")
cat("::: {.panel}", "\n", "[Second Tab]{.panel-name}", "\n")
plot(rnorm(150), main = "Plot 2")
cat(":::", "\n")
cat(":::::", "\n")

If we split the same code into multiple code chunks the panelsets do not work anymore, I guess because the div that opens for starting the panelset does not wrap the entire output, s. the following chunks:

```{r results='asis'}
cat("::::: {.panelset}", "\n")
cat("::: {.panel}", "\n", "[First Tab]{.panel-name}", "\n")
```{r results='asis'}
plot(rnorm(50), main = "Plot 1")
cat(":::", "\n")
```{r results='asis'}
cat("::: {.panel}", "\n", "[Second Tab]{.panel-name}", "\n")
plot(rnorm(150), main = "Plot 2")
cat(":::", "\n")
cat(":::::", "\n")

Since I want to insert panelsets programmatically via loop (with plots and tabs for a varying number of variables from a df), I would need a results='asis' option for distill that really inserts the results as they are, without any wrapping. Hope I could make clear(er) why this would be of help. Thanks a lot!

paneltest.zip

gplngr avatar Sep 27 '21 08:09 gplngr