How to embed 3D plot (rgl) into a html created via knitr?
There are several older posts looking for similar outcome. However, when I run all the sample codes i found. The rgl-plot don´t get embedded into the html created with knitr, but appears in an external window while "knitting" and disappears when the html page appears.
What I´m looking for is a way to integrate the 3D plot into the resulting html. I don´t mind whether it remains interactive or becomes static.
The following example is taken from the R Markdown Cookbook: https://bookdown.org/yihui/rmarkdown-cookbook/rgl-3d.html
title: Embed 3D plots with rgl
output: html_document
---
Set up a hook to save **rgl** plots:
```{r, setup}
library(rgl)
knitr::knit_hooks$set(webgl = hook_webgl)
```
See if it works for this 3D plot after we enable the hook
via the chunk option `webgl = TRUE`:
```{r, test-rgl, webgl=TRUE}
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col = rainbow(1000))
```