I'm creating a blog with blogdown
in which I compare code from R and code from Stata. I would like to show both codes so that the user can compare how it's done in R and in Stata. Howewer, putting two or more chunks in a row (code for R, code for Stata + output) makes the reading quite uncomfortable.
Several layouts came to my mind to include several chunks but I don't know if they are already implemented or if it's even possible to do so.
Have a button to display/hide chunks (one button per chunk)
One idea would be to have:
This person and this person succeeded in folding their code chunks in blogdown but apparently it hides or shows every chunks by default. How can I hide only some chunks by default? Is there an option (like the options eval
, echo
...) that hides or shows code chunk in blogdown
?
Chunks with "tabs"
The title of this part speaks for itself: is it possible to have tabs in a chunk so that we can switch from one code to the other (just like tabs in web browsers for example)?
Display two chunks side by side
In some blogdown
themes (maybe all, I don't know), the width is quite reduced and there is some unused space on the sides. Therefore, is it possible to increase the width on some parts of an article and to display two chunks side by side?
Any idea if one of these layouts can be realized in blogdown
?
I have found another alternative, that seems to be the best one so far: use panelsets of {xaringanExtra}
.
Panelsets work for {xaringan}
presentations as well as for R Markdown (and therefore {blogdown}
) outputs. See here for more options and details. Here's a small demo:
---
title: Title
output:
blogdown::html_page
---
```{r include = FALSE}
library(xaringanExtra)
# enable panelset
use_panelset()
```
## Title
Here's a simple way to display several code chunks in a concise way:
::::: {.panelset}
<!-- First panel -->
::: {.panel}
[R code]{.panel-name}
Check the R code below:
```{r echo = TRUE, eval = FALSE}
lm(mpg ~ drat, data = mtcars)
```
:::
<!-- Second panel -->
::: {.panel}
[Stata code]{.panel-name}
```
regress y x
```
:::
<!-- Third panel -->
::: {.panel}
[R output]{.panel-name}
```{r echo = FALSE, eval = TRUE}
lm(mpg ~ drat, data = mtcars)
```
:::
::::