### Bug description

panel-tabset does not work when I create the tabs/headings using a for loop and display a matplotlib chart under each heading. For example:

 

```{python}

from IPython.display import display, Markdown

import matplotlib.pyplot as plt

```

 

::: {.panel-tabset}

 

```{python}

for i in ["tab1 inside for loop", "tab2 inside for loop"]:

    display(Markdown(f"\n# {i}:\n"))

    fig = plt.figure()

    ax = fig.add_subplot(111)

    plt.show()

 

```

:::

 

Gives the following output, with no tabs:

 

![image](https://user-images.githubusercontent.com/47744152/179670032-34bf7688-d8aa-4089-8a1d-61b85ec8ea66.png)

 

In contrast, if the tabs/headings are not created inside a for loop the output is correct, with the tabs as expected:

 

::: {.panel-tabset}

 

### tab1 no for loop

```{python}

fig = plt.figure()

ax = fig.add_subplot(111)

```

 

### tab2 no for loop

```{python}

fig = plt.figure()

ax = fig.add_subplot(111)

```

:::

 

![image](https://user-images.githubusercontent.com/47744152/179670308-4f1c7cf9-bae6-42b4-8993-6137d9989287.png)

 

And if I create the tabs/headings inside a for loop, but only display text, the output is correct:

 

::: {.panel-tabset}

 

```{python}

for i in ['tab1 for loop no figure', 'tab2 for loop no figure']:

    display(Markdown(f"\n# {i}:\n"))

    display(Markdown("testing text"))

```

 

:::

 

![image](https://user-images.githubusercontent.com/47744152/179670650-6f5e47b6-3127-4fe3-8aff-be3083f03f42.png)

 

My problem is that I would like to display matplotlib charts inside tabs, but the number of tabs depends on the input data and can vary. Currently that does not seem to be possible.

I'm using Windows 10.

### `quarto check` Output

```bash
[>] Checking Quarto installation......OK
      Version: 1.0.32
      Path: C:\Program Files\Quarto\bin\
      CodePage: 1252

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.10.5
      Path: C:/Users/kylie/AppData/Local/Programs/Python/Python310/python.exe
      Jupyter: 4.11.1
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.1.0
      Path: C:/PROGRA~1/R/R-41~1.0
      LibPaths:
        - C:/Users/kylie/Documents/R/win-library/4.1
        - C:/Program Files/R/R-4.1.0/library        
      rmarkdown: 2.11

[>] Checking Knitr engine render......OK
```

### `quarto tools check` Output

```bash
[>] Inspecting tools

Tool         Status            Installed     Latest  
chromium     Not installed     ---           869685  
tinytex      Not installed     ---           v2022.07
```

### Checklist

- [x] [formatted your issue](https://yihui.org/issue/#please-format-your-issue-correctly) so it is easier for us to read?
- [ ] included a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [x] documented the quarto version you're running, by pasting the output from running `quarto check` in the "Quarto Check Output" text area?
- [x] documented the version of the quarto tools you're running, by providing the output from running `quarto tools check` in the "Quarto Tools Check Output" text area?
- [ ] documented the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [x] documented which operating system you're running? If on Linux, please provide the specific distribution as well.
- [x] upgraded to the latest version, including your versions of R, the RStudio IDE, and relevant R packages?
2022-07-19T13:46:01Z
kylie-foster
bug
Future
open
panel-tabset not working with for loop that displays matplotlib charts
https://github.com/quarto-dev/quarto-cli/issues/1456