Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
gplngr opened this issue Sep 27, 2021 · 0 comments
Open

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

gplngr opened this issue Sep 27, 2021 · 0 comments

Comments

@gplngr
Copy link

@gplngr gplngr commented Sep 27, 2021

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

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

No branches or pull requests

1 participant