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

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

问题描述

在 R 统计包的世界中,rgl 允许我生成可以用鼠标旋转的 3d 图.有没有办法以便携式格式导出这些图,将它们加载到 Web 浏览器或其他第三方工具中并在那里旋转它们?我对 Web 浏览器解决方案特别感兴趣,因为这将允许我在内部 wiki 上共享绘图.

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)

注意:示例代码没有在我的浏览器(RStudio、Win7、Chrome)中自动打开,因为路径被破坏了.您可能需要使用:

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 代替.您需要一个转换器,但您的用户应该能够仅使用 (现代)浏览器.您可能需要修改以下代码才能获得正确的路径:

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天全站免登陆