R 3d绘图的旋转无法与Knitr和WebGL一起使用

问题描述:

我正在尝试使用rgl knitr和webgl在一个序列中绘制几个交互式3d图.

I am trying to use rgl knitr and webgl to plot several interactive 3d plots in a sequence.

我的行为很怪异:当尝试用鼠标旋转绘图时,每次拖动鼠标后它们似乎都回到了初始位置.这使得交互非常不直观.我注意到页面上的最后一个情节不受此影响,但其余所有情节都受到影响.

And I am getting quite a weird behavior: when trying to rotate the plots with a mouse they seem to get back to their initial position after each mouse drag. This makes the interaction quite unintuitive. I noticed that the last plot on a page is not affected by this, but all the rest are.

这可以在原始的编织示例中看到:

This can be seen on the original knitr example:

来源: https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.Rmd

图表: https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.html

请注意尝试旋转第一个和第二个图形时的差异.

Notice the differences when trying to rotate the first and second figure.

可能是什么原因?也许可以通过将一些附加参数传递给3d和rgl图来解决问题(无法找到任何参数)?还是knitr和webgl的次要错误?

What could be a potential cause? Maybe the problem can be solved by passing some additional parameters to the 3d and rgl plots (was not able to find any)? Or is it a minor bug of knitr and webgl?

这是 knitr 中的错误,已经开发版本中.原因是即使每个页面上有多个图,每个图的 rgl 都包含<script src="CanvasMatrix.js" type="text/javascript"></script>.我已删除了针织机一侧的这一行,因此CanvasMatrix.js仅加载一次.您提到的针织衫示例现在可以使用了.

This is a bug in knitr, and has been fixed in the development version. The reason for it is that rgl includes <script src="CanvasMatrix.js" type="text/javascript"></script> for every plot, even when there are multiple plots on the same page. I have removed this line on knitr's side, so that CanvasMatrix.js is only loaded once. The knitr example you mentioned works now.