Reputation: 111
I'm trying to build a flexdashboard which includes an rgl widget to display some multivariate data. The problem is identical to 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 from Duncan himself, and wasn't able to implement a solution with what was said there either. I don't have the reprex package, nor have I used it before, and I'm a little pressed for time, so here's my best attempt at a reprex with the formatting I'm attempting to use.
---
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()
When I knit the .rmd file, I don't see any errors, nothing obviously appears to go wrong during knit. And when I inspect the .html file I find the rglwidget element within the html code, but the space where it should be is still blank. The widget device will show up in the console if I run the code outside of markdown though, just not in the final document. This doesn't work with flexdashboard output either.
Here's my session info. I'm using 32-bit R because the data is coming from an access database and I need to keep architecture compatible:
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
Upvotes: 1
Views: 401
Reputation: 111
Solved. It was there the whole time. The renderer that comes with Rstudio wasn't rendering the widget. As soon as I opened my window in a web browser that supports webGL, then bang! There it was. Not sure if this something that the Rstudio team needs to know about, or if webGL is even something that they want to incorporate within the IDE.
Anyway, cheers everyone.
Upvotes: 0
Reputation: 814
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)
A full working example:
---
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")
This shouldn't be necessary, but it's a hack for now I reckon.
Upvotes: 1