dmurdoch / rgl

rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
https://dmurdoch.github.io/rgl/
GNU General Public License v2.0
85 stars 20 forks source link

Code and output messed up in R Markdown after rgl plot #302

Open dmurdoch opened 1 year ago

dmurdoch commented 1 year ago

If the chunk option has collapse = TRUE and any htmlwidget (including one from rgl) is displayed there, then code and output following the widget will not be formatted properly.

Problematically, the rmarkdown::html_vignette template defaults to collapse = TRUE.

This is a knitr issue, fixed in https://github.com/yihui/knitr/pull/2212. That fix is included in knitr version 1.42.3, currently only on Github. You can install it with

remotes::install_github("yihui/knitr")
dmurdoch commented 1 year ago

A workaround if you want collapse = TRUE is to end any chunk at the point where it shows an rgl (or other htmlwidget) display, and start a new chunk afterwards. For example, change this:

```{r collapse = TRUE}
xyz <- matrix(rnorm(30), ncol = 3)
plot3d(xyz)
plot3d(xyz, type = "s")

to this:
xyz <- matrix(rnorm(30), ncol = 3)
plot3d(xyz)
plot3d(xyz, type = "s")

Another workaround is to use chunk option `fig.show = "hold"`, which will display all the `rgl` figures after the chunk, instead of showing them as they are completed.  For example,
xyz <- matrix(rnorm(30), ncol = 3)
plot3d(xyz)
plot3d(xyz, type = "s")