R:使用RGL生成可以在Web浏览器中查看3D可旋转的情节? [英] R: using rgl to generate 3d rotatable plots that can be viewed in a web browser?

查看:497
本文介绍了R:使用RGL生成可以在Web浏览器中查看3D可旋转的情节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R统计数据包的世界,RGL可以让我产生3D绘图,我可以用我的鼠标旋转。有没有一种方法可以让我在一个便携格式导出这些地块,加载它们在Web浏览器或其他第三方工具和旋转它们呢?我在Web浏览器的解决方案非常感兴趣,因为这将让我在内部维基共享地块。

In the world of the R statistics package, rgl allows me to generate 3d plots that I can rotate with my mouse. Is there a way I can export these plots in a portable format, load them in a web browser or other third party tool and rotate them there? I Am especially interested in the web browser solution since this will allow me to share the plots on an internal wiki.

如果RGL不允许这样,是否有其他库或策略,让我做到这一点?

If rgl does not allow this, are there other libraries or strategies that would allow me to accomplish this?

推荐答案

您可以尝试 vrmlgen 包。它将产生可与浏览器插件被显示的3d VRML文件;你可以找到一个插件在 VRML插件和浏览器检测的。

You could try the vrmlgen package. It will produce 3d VRML files that can be displayed with a browser plugin; you can find a plugin at VRML Plugin and Browser Detector.

一旦你安装一个插件,试试这个:

Once you've installed a plugin, try this:

require(vrmlgen)
example(bar3d)

注:这个例子code并没有为我的浏览器(RStudio,Win7的,铬),因为该路径得到了错位自动打开。您可能需要使用:

NB: the example code didn't automatically open in a browser for me (RStudio, Win7, Chrome) because the path got mangled. You might need to use:

require(stringr)
browseURL(str_replace_all(file.path(outdir, 'barplot.html'), fixed('\\'), '/'))

如果你不想安装插件,VRML,你可以使用X3DOM代替。你需要一个转换的,但你的用户应该能够只是一个(现代)浏览器中查看。您可能需要修改以下code,以获得正确的路径:

If you don't want to install a VRML plugin, you could use X3DOM instead. You'll need a converter, but your users should be able to view them with just a (modern) browser. You might have to modify the following code to get the paths right:

setwd(outdir)
aopt <- 'C:/PROGRA~1/INSTAN~1/bin/aopt' # Path to conversion program
vrml <- 'barplot.wrl'
x3dom <- 'barx.html'
command <- paste(aopt, '-i', vrml, '-N', x3dom)
system(command)
# LOG   Avalon   Init: 47/616, V2.0.0 build: R-21023 Jan 12 2011
# LOG   Avalon   Read url
# LOG   Avalon   Read time: 0.074000
# ============================================
# Call: writeHTML with 1 param 
# Write raw-data to barx.html as text/html
# WARNING   Avalon   Run NodeNameSpace "scene" destructor and _nodeCount == 3
# WARNING   Avalon   Try to remove nodes from parents
# WARNING   Avalon   PopupText without component, cannot unregister
# WARNING   Avalon   Avalon::exitSystem() call and node/obj left: 0/3331
browseURL(file.path(outdir, 'barx.html'))
setwd(curdir)

这篇关于R:使用RGL生成可以在Web浏览器中查看3D可旋转的情节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆