在 flexdashboard 和 rmarkdown 中嵌入 rglwidget 时出现问题

Trouble embedding an rglwidget within flexdashboard and rmarkdown

我正在尝试构建一个 flexdashboard,其中包含一个 rgl 小部件以显示一些多元数据。该问题与 Duncan 本人的 this post, where the widget I'm trying to create doesn't appear in the final document. Unfortunately the comments within the post didn't help me with my solution, (I re-installed the rgl package from the forge repo) and there weren't any answers posted. I've also looked at this post 相同,并且无法根据那里所说的内容实施解决方案。我没有 reprex 包,以前也没有用过,而且时间有点紧,所以这是我对 reprex 的最佳尝试,我尝试使用的格式。

---
title: "3d widget"
output: html_document
knitr::opts_chunk$set(echo = TRUE)

library(rgl)

with(mtcars, plot3d(x = mpg,
                    y = disp,
                    z = hp,
                    col = cyl,
                    size = 1,
                    type = "s",
                    axes = FALSE,
                    xlab = "",
                    ylab = "",
                    zlab = ""))
rglwidget()

当我编织 .rmd 文件时,我没有看到任何错误,在编织过程中似乎没有任何明显的错误。当我检查 .html 文件时,我在 html 代码中找到了 rglwidget 元素,但是 space 它应该在的地方仍然是空白的。如果我 运行 markdown 之外的代码,小部件设备将显示在控制台中,只是不在最终文档中。这也不适用于 flexdashboard 输出。

这是我的会话信息。我正在使用 32 位 R,因为数据来自访问数据库,我需要保持体系结构兼容:

R version 3.6.0 (2019-04-26)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.100.51

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3              digest_0.6.20           later_0.8.0             mime_0.7               
 [5] R6_2.4.0                jsonlite_1.6            xtable_1.8-4            magrittr_1.5           
 [9] evaluate_0.14           rlang_0.4.4             miniUI_0.1.1.1          promises_1.0.1         
[13] rmarkdown_2.1           webshot_0.5.1           tools_3.6.0             manipulateWidget_0.10.0
[17] htmlwidgets_1.3         crosstalk_1.0.0         shiny_1.3.2             httpuv_1.5.1           
[21] xfun_0.7                yaml_2.2.0              compiler_3.6.0          htmltools_0.4.0        
[25] knitr_1.28

It appears that it's a problem with RStudio 1.2. As a workaround that worked for me, insert this line of code before loading rgl like RStudio community suggests:

options(rgl.useNULL=TRUE) 

一个完整的工作示例:

---
title: Embed 3D plots with rgl
output: html_document
---


```{r, setup}
options(rgl.useNULL=TRUE) 
library(rgl)


```{r testrgl}
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)


plot3d(x, y, z, col = rainbow(1000))
rglwidget(elementId = "plot3drgl")

这应该不是必需的,但我认为这是一个 hack。

已解决。它一直在那里。 Rstudio 附带的渲染器未渲染小部件。当我在支持 webGL 的网络浏览器中打开 window 时,砰!就在那里。不确定这是否是 Rstudio 团队需要了解的,或者 webGL 是否是他们想要合并到 IDE.

中的东西

总之,大家加油