微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R:rgl layout3D 破坏了 RMarkdown 中的播放小部件

如何解决R:rgl layout3D 破坏了 RMarkdown 中的播放小部件

我正在创建一个 Rmarkdown 报告,其中我使用了一个 layout3D() 多重图和一个带有滑块的 playwidget() 图。如果我运行下面的代码,一切正常,但如果我想先显示多个图,然后显示滑块(所以只需更改最后两个单元格的顺序)我的滑块坏了,所有点都显示出来了,滑块没有小部件中的任何更改。同样的问题,如果我想显示一个滑块,然后是一个多图,然后是另一个滑块:第一个滑块工作正常,但第二个没有。我想这与保持“链接”到以下滑块的多个图的输出有关。

一个(可能相关的)问题是如何将函数返回的单个对象中的所有多个图分组,就像滑块一样。这就是为什么我需要在函数调用添加 rglwidget() 以便在单元格中显示绘图。

谢谢

---
title: Test
output:
  html_document
---


```{r,echo=FALSE,include=FALSE,fig.height = 13,fig.width = 13}
suppressMessages(suppressWarnings(library(rgl)))
options(rgl.useNULL = TRUE) # Suppress the separate window.

# define function
fun_playwidget = function(){

clear3d()    
setosa <- with(subset(iris,Species == "setosa"),spheres3d(Sepal.Length,Sepal.Width,Petal.Length,col=as.numeric(Species),radius = 0.211))
versicolor <- with(subset(iris,Species == "versicolor"),radius = 0.211))
out = rglwidget() %>%
playwidget(start = 0,stop = 1,interval = 1,subsetControl(1,subsets = list(
                 Setosa = setosa,Versicolor = versicolor
                 )))

return(out)
}

fun_layout3D = function(){
  shapes <- list(Tetrahedron = tetrahedron3d(),Cube = cube3d(),Octahedron =  octahedron3d(),Icosahedron = icosahedron3d(),Dodecahedron = dodecahedron3d(),Cuboctahedron = cuboctahedron3d())
col <- rainbow(6)
open3d()

mat <- matrix(1:4,2,2)
mat <- rbind(mat,mat + 4,mat + 8)
layout3d(mat,height = rep(c(3,1),3),sharedMouse = TRUE)
for (i in 1:6) {
  next3d()
  plot3d(shapes[[i]],col = col[i])
  next3d()
  text3d(0,names(shapes)[i])
}
}
```

# playwidget
```{r,include=TRUE,fig.height = 5,fig.width = 5,webgl=TRUE}
fun_playwidget()
```

# layout3d
```{r,webgl=TRUE}
fun_layout3D()
rglwidget()
```

编辑:似乎 rglwidget() 之后的 fun_layout3D() 破坏了渲染,使得圆点被绘制为图中的正方形(数据不同)

enter image description here

编辑 2:这是最小的例子。这会产生两个问题:点呈现为正方形并且滑块不移动。

---
title: Test
output:
  html_document
---


```{r,Versicolor = versicolor
                 )))

return(out)
}

fun_layout3D = function(){
clear3d()
  mat <- matrix(1:2,ncol = 2)
  layout3d(mat,height = c(2,2),widths = c(2,sharedMouse = T)
  data = matrix(sample.int(100,81),ncol = 3)
  next3d()
  plot3d(xyz.coords(data),col = "blue",type = "p",size = 30)
  next3d()
  plot3d(xyz.coords(data),col = "red",size = 30)
  rglwidget()
}
```


# layout3d
```{r,fig.width = 5}
fun_layout3D()

```

# playwidget
```{r,fig.width = 5}
fun_playwidget()
```

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。