Rmarkdown 文件中的 Rayshader?

Dan*_*iii 4 r r-markdown rayshader

当我渲染 Rayshader 图形时,它会在我的 mac 上打开 Xquartz,没问题,但是如果我想将它包含在我的 Rmarkdown 文档中,它只显示代码,没有图形,该怎么办?我知道这是一个繁重的图形密集型渲染,但正在寻找任何提示。谢谢,下面是我的代码:

---
title: "rayshader"
author: "Daniel"
date: "6/16/2020"
output: 
  html_document:
  self_contained: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r cars}
library(rayshader)

#Here, I load a map with the raster package.
loadzip = tempfile() 
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)

#And convert it to a matrix:
elmat = raster_to_matrix(localtif)

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color = "desert") %>%
  add_shadow(ray_shade(elmat, zscale = 3), 0.5) %>%
  add_shadow(ambient_shade(elmat), 0) %>%
  plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
```
Run Code Online (Sandbox Code Playgroud)

小智 5

来自包所有者:

要将绘图嵌入到 RMarkdown 文档中,您需要rgl::rglwidget()在显示绘图后调用。如果您要嵌入多个绘图,则在绘制下一个绘图之前,您还必须关闭上rgl::rgl.close()一个绘图。

参考

为我工作。