[R] snapshot3d hangs during rmarkdown::render
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Thu Jun 10 15:24:53 CEST 2021
On 10/06/2021 4:42 a.m., David Waterman wrote:
> Hi all,
>
> I tried subscribing to the list yesterday, but this does not appear to
> have been successful. Therefore I am hoping this message meets
> volunteer moderator approval.
>
> I have problems using snapshot3d from rgl while trying to render an R
> Markdown page. I want to do this to capture static snapshots of an
> interactive widget on the page. I had this working with an earlier
> version of R (sorry, forgot which), but this now hangs indefinitely at
> the snapshot3d call.
>
> Should I expect this to work? I can successfully create a snapshot
> from an interactive R session with either webshot=TRUE or FALSE, just
> not from within my R Markdown build.
>
> I have created a simple reproducer, which I attempt to build using:
>
> library(rmarkdown)
> rmarkdown::render("reproducer.Rmd")
>
> where the contents of reproducer.Rmd are:
>
> $ cat reproducer.Rmd
> ---
> title: "rgl test"
> output:
> html_document:
> toc: true
> toc_float:
> toc_collapsed: true
> ---
>
> ```{r, setup, echo=FALSE}
> library(rgl)
> library(knitr)
> knitr::knit_hooks$set(webgl = hook_webgl)
> ```
>
> ### Insert rgl figure
>
> Test
>
> ```{r, webgl=TRUE, echo=FALSE}
> with(iris, plot3d(Sepal.Length, Sepal.Width, Petal.Length,
> type="s", col=as.numeric(Species)))
> snapshot3d("foo.png")
> rglwidget()
> rgl.close()
> ```
One suggestion I forgot: try snapshot3d("foo.png", webshot = FALSE).
This should fall back to the internal snapshot code in rgl. You
generally don't get as good quality of a result, but if you are not
running on a headless system it will generally work.
Duncan Murdoch
More information about the R-help
mailing list