How can I get a rayshader plot to appear in a HTML document made via Rmd? Simple example in gist at: rayshader rmd · GitHub
When I try to knit this, there is a space for the rayshader output but nothing appears.
mara
May 25, 2021, 6:14pm
2
This is a bit of a shot in the dark, as I haven't tried it myself, but can it be done inside a rglwidget?
opened 11:09AM - 03 Jan 17 UTC
closed 03:49PM - 24 Oct 17 UTC
question
I needed to generate 3D plots using nested `Rmd` files and `rgl` and it looks li… ke there's an issue with how `rmarkdown/knitr` interacts with `rgl`. Here's a minimal reproducible example.
`parent.Rmd` contains:
<pre>
---
title: 3D
output:
html_document
---
```{r 3dplots}
library(rmarkdown)
render("child.Rmd", output_file = "first.html")
render("child.Rmd", output_file = "second.html")
```
</pre>
`child.Rmd` contains:
<pre>
---
title: "3D plots"
---
```{r echo = FALSE, warning = FALSE}
library(rgl)
plot3d(runif(50), runif(50), runif(50), type = "s")
rglwidget(width = 400, height = 800)
```
</pre>
`first.html`, generated by running `rmarkdown::render("parent.Rmd")`, leads to a proper `HTML` with the 3-dimensional plot. However, `second.html` doesn't have the plot of the 3D object (it has the title though). Inspecting `HTML` source show that the `rgl` object is indeed there and that `copyObj()` method failed in `rglwidgetClass` for this second `HTML`.
Here's my session info.
<pre>
## R version 3.3.2 (2016-10-31)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.1 LTS
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] rgl_0.96.0 rmarkdown_1.2
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.8 digest_0.6.10 rprojroot_1.1 mime_0.5
## [5] R6_2.2.0 xtable_1.8-2 jsonlite_1.1 backports_1.0.4
## [9] magrittr_1.5 evaluate_0.10 stringi_1.1.2 tools_3.3.2
## [13] stringr_1.1.0 htmlwidgets_0.8 shiny_0.14.2 httpuv_1.3.3
## [17] yaml_2.1.14 htmltools_0.3.5 knitr_1.15.1
</pre>
tyler
May 25, 2021, 7:46pm
3
Is it just the snapshot you're interested in, or a 3D widget? You can get the latter by calling rgl::rglwidget()
before rgl::rgl.close()
. Also, is the snapshot not appearing when you run the code interactively, and are you knitting this document on your local computer? Using rgl on headless (remote servers, usually) machines is fairly difficult, but locally it shouldn't be an issue.
Thanks - I'll test that out tonight and ideally want a 3D widget. It runs interactively but not when I knit. I'm running this all locally on my PC, not a server for both the toy example and my real data.
system
Closed
June 15, 2021, 8:03pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.