displaying plots inside tabs in Rmarkdown

Open
#784 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, r

Research direction

Begin by reproducing the report with the attached plots.Rmd.zip and the two Python chunks using plotnine and seaborn. Trace how their output is handled when results="asis" is used inside R Markdown tabsets; done means each generated plot appears in its intended tab and the seaborn tabs are produced correctly.

Written by the indexing model from the issue text.

Description

If I try to display python plots inside tabs in Rmarkdown I get strange results:

Rmarkdown file attached
plots.Rmd.zip

## PLots

Trying to use plotnine, looks OK.

```{python}
import matplotlib
matplotlib.use('Agg')
from plotnine import ggplot, aes, geom_bar
from plotnine.data import mpg

p = ggplot(mpg) + geom_bar(aes(x="class"))

p

trying to use seaborn, looks OK.


import seaborn as sns

mpg.head()
sns.distplot(mpg.hwy);

Tabed Plotnine Plots {- .tabset .tabset-pills}

OK, with what we learned before, let's do then some plotnine plots inside tabs. Hmm, the tabs are produced,
but all the plots are acumulated on the final tab, the first two don't have anything. Actually you have to
click on the third tab if you want to show what is coming after.


conditions = ["class", "drv", "manufacturer"]

for condition in conditions:
	print(f"### {condition} \n")

print('\n\n<!-- -->\n\n')

p = ggplot(mpg) + \
geom_bar(aes(x=condition))
p

print('\n\n<!-- -->\n\n')

print('\n\n<!-- -->\n\n')

Tabed Seaborn Plots {- .tabset .tabset-pills}

and with seaborn? Hmm strange results as well, this time no tabs.

import matplotlib.pyplot as plt

conditions = ["class", "drv", "manufacturer"]

for condition in conditions:
	print(f"### {condition} \n")

print('\n\n<!-- -->\n\n')
plt.figure()
sns.countplot(x=condition, data=mpg)


print('\n\n<!-- -->\n\n')
Dominant language
R
Stars
1.8k
Forks
349
Avg merge
5h 13m
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/reticulate

All issues in rstudio/reticulate

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.