在 Rstudio 中,我使用“rgl”包生成 3d 绘图,然后使用“knitr”将它们转换为用户可以交互的 html 文件。我遇到了几个我认为是独立的问题,但希望一次解决一个问题(万一它们不是!)
作为测试,我使用了来自网络的少量代码来生成绘图,然后尝试将其转换为 html 文件(代码如下)。请注意,我正在使用较新且推荐的 rglwidget() 方法。
当生成的 html 文件出现在 RStudio 查看器中时,它没有显示任何绘图(只是留下了一个空格),但最终我发现该 html 文件在使用常规浏览器(即 Chrome 或 Edge)查看时可以按预期工作。 (但其他测试图确实按预期显示在 RStudio 查看器中。)
请有人尝试“编织”下面的代码并让我知道他们是否在 RStudio html 查看器中看到了该图?如果我不是很密集并且这是一个“真正的”问题,任何人都可以阐明 RStudio 浏览器无法正确显示的情况。 (我只遇到了 html 中出现的其他绘图的部分问题,但这些部分在 html 查看器上似乎是一致的,这表明对我来说这是一个单独的问题,但我想对这个基本问题进行排序 - 但令人不安 - 首先列出一个)
我在 Windows 10 下使用最新版本的 R、RStudio、rgl(来自 Cran)和 knit
非常感谢您的帮助。
Alex
下面是我正在使用的 Rmarkdown 文件
---
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.