4

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.
A Sutton
  • 83
  • 5
  • hi it's working if you remove the `open3d()` – s.brunel Apr 11 '17 at 13:12
  • thanks for the speedy look v. much appreciated. I deleted the line: open3d() and I still get the same problem i.e. html file created has gap and no figure in RStudio but looks fine in browser. RStudio generates the plot in a separate window transiently while knitr does its thing and that looks fine also (with or without the line). – A Sutton Apr 11 '17 at 18:30
  • Looking into this further it seems a possible glitch between knitr created html viewer in RStudio and layout3d() function in rgl below I strip the code to 2 rgl instances 1 label and 1 shape. Only the shape is plotted.i.e code becoms --- title: "3d shape example from the web" output: html_document --- ```{r testshape} library(rgl) cols <- rainbow(7) layout3d(matrix(1:2, 1,2), heights=c(1,3)) text3d(0,0,0,"tetrahedron3d"); next3d() shade3d(tetrahedron3d(col=cols[1])) rglwidget() ``` – A Sutton Apr 11 '17 at 19:06
  • You could try the unreleased rgl version. To get it, see the instructions here: http://stackoverflow.com/questions/37142762/how-do-i-install-the-latest-version-of-rgl . More generally, reporting actual version numbers (rather than "latest versions") is helpful. – user2554330 Apr 16 '17 at 18:40
  • Perhaps: `?writeWebGL` or `?rglwidgetOutput` – IRTFM Apr 17 '17 at 00:40

0 Answers0