Two {python} chunks produce plots using matplotlib. If I place an {r} chunk between them, then knitr replaces the first plot by the second. Anyone know how to fix this behavior?
Minimal example Rmd file:
---
title: "Error demo"
date: "`r Sys.Date()`"
---
```{r setup, include=FALSE}
library(reticulate)
use_condaenv('/Users/XXXX/opt/anaconda3/envs/r-env1', required = TRUE)
```
```{python, echo=FALSE}
import matplotlib.pyplot as plt
plt.plot([4,1,2,0],'r-')
```
```{r, echo = FALSE}
# an r chunk between the python chunks suppresses the first plot
```
```{python, echo=FALSE}
plt.plot([0,2,1,4],'g-')
```
The build output contains two versions of the second plot. Here is the relevant part of the HTML output:
<div id="header">
<h1 class="title">Error demo</h1>
<p class="date" style="margin-top: 1.5em;"><em>2021-05-07</em></p>
</div>
<p><img src="MIB-R_files/figure-html/unnamed-chunk-1-1.png" width="672" /></p>
<p><img src="MIB-R_files/figure-html/unnamed-chunk-1-1.png" width="672" /></p>
Version info:
- MacOS: Darwin 20.3.0
- Python: 3.9.2 | packaged by conda-forge
- RStudio: 1.4.1106
- rmarkdown: 2.8
- knitr: 1.33
- reticulate: 1.20