In Rstudio I am using the 'rgl' package to produce 3d plots and then 'knitr' to turn these into html files that the user can interact with. I have run into a couple of issues that I think are independent but hoping to resolve one at a time (in case they are not!)
As a test, I used a small amount of code from the web to produce plots that I then tried to turn into html files (code given below). Note I am using the newer and recommended rglwidget() approach.
The html file produced did not show any of the plot (just left a space) when it appeared in the RStudio viewer, but eventually I discovered that the html file works as intended when viewed with a regular browser (i.e. Chrome or Edge). (But other test plots do show up in the RStudio viewer as expected.)
Please could someone try to 'knit' the code below and let me know whether they see the plot in the RStudio html viewer or not? If I am not being dense and this is a 'real' issue can anyone shed light on situations when the RStudio browser will fail to display correctly. (I am getting issues with only parts of other plots appearing in the html, but the parts seem consistent over html viewers which suggests to me it is a separate issue but I want to sort this basic - but disconcerting - one out first)
I am using the latest versions of R, RStudio, rgl (from Cran) and knitr under Windows 10
Many thanks in advance for any help.
Alex
Below is the Rmarkdown file I am using
---
title: "3d shape example from the web"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r test3, echo=FALSE}
library(rgl)
open3d()
cols <- rainbow(7)
layout3d(matrix(1:16, 4,4), heights=c(1,3,1,3))
text3d(0,0,0,"tetrahedron3d"); next3d()
shade3d(tetrahedron3d(col=cols[1])); next3d()
text3d(0,0,0,"cube3d"); next3d()
shade3d(cube3d(col=cols[2])); next3d()
text3d(0,0,0,"octahedron3d"); next3d()
shade3d(octahedron3d(col=cols[3])); next3d()
text3d(0,0,0,"dodecahedron3d"); next3d()
shade3d(dodecahedron3d(col=cols[4])); next3d()
text3d(0,0,0,"icosahedron3d"); next3d()
shade3d(icosahedron3d(col=cols[5])); next3d()
text3d(0,0,0,"cuboctahedron3d"); next3d()
shade3d(cuboctahedron3d(col=cols[6])); next3d()
text3d(0,0,0,"oh3d"); next3d()
shade3d(oh3d(col=cols[7]))
rglwidget()
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.