The quarto-panelize
extension allows you to tabbify existing code cells to show their source or add interactivity.
To install the quarto-panelize
extension, follow these steps:
-
Enter a Quarto project.
-
Open your terminal inside the Quarto project.
-
Run the following command:
quarto add coatless-quarto/panelize
If you wish to make your code interactive, please install the following Quarto extensions:
# For Python
quarto add coatless-quarto/pyodide
# For R
quarto add coatless/quarto-webr
These commands will download and install the extension as well as any dependencies under the _extensions
subdirectory of your Quarto project. If you are using version control, ensure that you include this directory in your repository.
For each document, place the panelize
filter in the document's header:
filters:
- panelize
Then, wrap existing R or Python code cells using a Div
and specify the a panelize class.
Supported options include:
Class | Description |
---|---|
.to-source |
Convert a code cell to show rendered output and its source. |
.to-pyodide |
Convert code cell from static Python code to interactive Python code using Pyodide. |
.to-webr |
Convert code cell from static R code to interactive R code using webR. |
For example, if we have a code cell with R that we want to show its options, then we use:
:::{.to-source}
```{r}
#| echo: fenced
#| eval: true
1 + 1
```
:::
This will generate output equivalent to:
:::{.panel-tabset}
### Results
```{r}
#| eval: true
1 + 1
```
### Source
```{{r}}
#| eval: true
1 + 1
```
:::
For creating a tabset that contains both rendered results and interactive option, modify the document header and place the desired extension filter after panelize
, e.g.
filters:
- panelize
- pyodide
- webr
Important
Order matters! Please make sure to place the filters after panelize
.
Otherwise, the interactivity filter will not detect the code cell!
Next, wrap the existing code cell using a Div
with a class of either .to-pyodide
or .to-webr
.
For Python, that looks like:
:::{.to-pyodide}
```{python}
4 + 5
```
:::
For R, that looks like:
:::{.to-webr}
```{r}
1 + 1
```
:::
Thanks to @mcanouil and @cscheid who provided great insight into approaching this problem by re-orienting it in a way that is more managable. Please see the full discussion.