Skip to content

Commit 58d5601

Browse files
committed
demonstrate multi-table output for python
1 parent 51d5be7 commit 58d5601

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

docs/authoring/tables.qmd

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,36 +279,48 @@ kable(head(cars))
279279

280280
If your code cell produces multiple tables, you can also specify subcaptions and layout using cell options:
281281

282-
::: {.panel-tabset}
283-
## R
282+
::: {.panel-tabset group="language"}
283+
284+
## Python
284285

285-
``` {.r}
286+
````python
287+
```{{python}}
286288
#| label: tbl-example
287289
#| tbl-cap: "Example"
288290
#| tbl-subcap:
289-
#| - "Cars"
290-
#| - "Pressure"
291+
#| - "MPG"
292+
#| - "Taxis"
291293
#| layout-ncol: 2
292-
#| echo: fenced
293294

294-
library(knitr)
295-
kable(head(cars))
296-
kable(head(pressure))
295+
import seaborn as sns
296+
from IPython.display import Markdown, display
297+
mpg = sns.load_dataset("mpg").head(10)
298+
taxis = sns.load_dataset("taxis").head(10)
299+
300+
display(Markdown(mpg.to_markdown(index = False)))
301+
display(Markdown(taxis.to_markdown(index = False)))
297302
```
303+
````
298304

299-
## Python
305+
Note that we use the [`display()`](https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display) function imported from `IPython` so that we can render multiple outputs from a single cell (by default cells only output their last expression).
306+
307+
## R
300308

301-
``` {.python}
309+
````python
310+
```{{r}}
302311
#| label: tbl-example
303312
#| tbl-cap: "Example"
304313
#| tbl-subcap:
305314
#| - "Cars"
306315
#| - "Pressure"
307316
#| layout-ncol: 2
308-
#| echo: fenced
309317

310-
Markdown(cars + pressure)
318+
library(knitr)
319+
kable(head(cars))
320+
kable(head(pressure))
311321
```
322+
````
323+
312324

313325
:::
314326

0 commit comments

Comments
 (0)