rgl/webgl & shiny for interactive 3d plots

1,630 views
Skip to first unread message

Greg Jefferis

unread,
Dec 1, 2012, 8:03:40 PM12/1/12
to shiny-...@googlegroups.com
Hello,

I've had a quick play with shiny and already see a number of possible problems that it could solve for me. Many thanks to the creators their hard work! However a lot of my work involves (interactive) 3D plots for which I use the rgl package. Recently I have made use of the writeWebGL function to make interactive 3d plots that can be visualised in the browser. Basically this used HTML5 + webgl and it works pretty well. It would be really nice if one could easily combine these two approaches to vary e.g. parameters controlling the plots. Would anyone have any suggestions for how to do this?

Many thanks,

Greg Jefferis
Cambridge, UK.

Joe Cheng

unread,
Dec 5, 2012, 11:52:00 AM12/5/12
to shiny-...@googlegroups.com
Shiny has an htmlOutput widget that can be inserted into your Shiny app and receive arbitrary HTML. In theory you could take the webgl HTML that is outputted by rgl, and assign it in a reactive function to the output HTML:

output$webglPlot <- reactive(function() {
  // webgl generating code here, return an HTML string
})

Some things you'll have to deal with:
  • By default, rgl's webgl mode outputs an entire HTML page including head and body tags, which is not quite what you want. You'll have to provide a template argument to writeWebGL, the path of a file whose entire contents are below.
  • writeWebGL writes its output to a file, not a string, so you'll have to create a temp file and read in the contents. Don't forget to delete the temp file before leaving the function.
  • writeWebGL takes a prefix for disambiguating different scenes on the same page. You might want to generate a random prefix for each scene that you generate.

Even with all this I'm not sure if it will work, but it sure seems worth a shot. There's no inherent reason why WebGL shouldn't work with Shiny, so I'm sure that if nothing else some tweaking to rgl would make it possible. If you figure out how to get it going it would be amazing to have a reactiveWebGL function that wraps up the call to writeWebGL for you--we can help you with that if you need.


template.html:

%WebGL%
<script>setTimeout(function() { webGLStart(); }, 100);</script>



--
 
 

Jeff Allen

unread,
Jan 9, 2013, 11:46:02 PM1/9/13
to shiny-...@googlegroups.com
I was able to get something working on a private Shiny Server instance (as RGL has some dependencies which aren't available on Glimmer). You can take a look here:
https://www.trestletechnology.net/2013/01/visualize-color-palettes-in-interactive-3d-grid-shiny-rgl/

The source is available on Github if you want to play around with it: https://github.com/trestletech/shiny-sandbox/tree/master/rgl

Enjoy!
Jeff

Joe Cheng

unread,
Jan 10, 2013, 6:30:10 PM1/10/13
to shiny-...@googlegroups.com
That's great, and the reactiveWebGL function and webGLParser.R look very easy to reuse! Maybe reactiveWebGL could even become part of the rgl package, eventually...


--
 
 

John Muschelli

unread,
Apr 20, 2013, 12:36:06 PM4/20/13
to shiny-...@googlegroups.com
Is there any possibility of installing the dependencies on Glimmer for RGL?  I understand this is a slippery slope question (ie rggobi/any other package that has sizable dependencies is open to question).  But I do think some users are trying RGL with shiny (in my case brain images) and we have a non-R audience.  

I think private servers are still a good option but we're still testing things out in glimmer.

Does anyone see of a way to submit dependency requests that wouldn't become inundating?

Winston Chang

unread,
Apr 26, 2013, 4:09:29 PM4/26/13
to shiny-...@googlegroups.com
Hi, this is something we had looked at installing on Glimmer in the past, but we decided against it for security and resource reasons. However, after a more recent look, it seems that these might not be a problem after all, so we've installed the required packages there. You should now be able to install rgl on Glimmer.

-Winston


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gregory Jefferis

unread,
Apr 26, 2013, 4:13:06 PM4/26/13
to shiny-...@googlegroups.com

On 26 Apr 2013, at 21:09, Winston Chang wrote:

Hi, this is something we had looked at installing on Glimmer in the past, but we decided against it for security and resource reasons. However, after a more recent look, it seems that these might not be a problem after all, so we've installed the required packages there. You should now be able to install rgl on Glimmer.

Great! 

Is glimmer a dedicated host or a vm? I had great difficulty trying to get rgl running on a centos 6.1 VM.

Thanks,

Greg Jefferis.

--
Gregory Jefferis, PhD                      
Division of Neurobiology
MRC Laboratory of Molecular Biology 
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis

Winston Chang

unread,
Apr 26, 2013, 4:18:38 PM4/26/13
to shiny-...@googlegroups.com
It's a VM. You may need Xvfb (X virtual framebuffer device) to install it on a headless system. IIRC, Xvfb isn't actually run when rgl is used, but it's needed to install various GL-related packages used by rgl.

-Winston


uz...@ucdavis.edu

unread,
May 9, 2013, 3:43:07 AM5/9/13
to shiny-...@googlegroups.com
I tried to install rgl on glimmer, and I got such error message.

Warning in rgl.init(initValue) : RGL: unable to open X11 display
Warning in fun(libname, pkgname) : error in rgl_init

I copied Jeff's code but it doesn't work. The place where should be the plot is
Error rgl_dev_getcurrent

在 2013年4月27日星期六UTC+8上午4时09分29秒,Winston Chang写道:

Winston Chang

unread,
May 9, 2013, 10:30:46 AM5/9/13
to shiny-...@googlegroups.com
We're still trying to figure out whether rgl is something that can be used safely on glimmer. Please see here:
https://groups.google.com/d/msg/shiny-discuss/SC6M8NfUKDI/LGZWESNLvKcJ

-Winston

Duncan Murdoch

unread,
Jul 5, 2013, 2:58:50 PM7/5/13
to shiny-...@googlegroups.com


On Wednesday, January 9, 2013 11:46:02 PM UTC-5, Jeff Allen wrote:
I was able to get something working on a private Shiny Server instance (as RGL has some dependencies which aren't available on Glimmer). You can take a look here:
https://www.trestletechnology.net/2013/01/visualize-color-palettes-in-interactive-3d-grid-shiny-rgl/

The source is available on Github if you want to play around with it: https://github.com/trestletech/shiny-sandbox/tree/master/rgl

Stéphane Laurent pointed me to this thread.  I haven't tried out your code, but if you have suggested additions to rgl that would make it easier, let me know.

By the way,
Stéphane also found someone who tracked down a bug in the way rgl's writeWebGL was interacting with the ANGLE WebGL engine that's used in Chrome and recent verisons of Firefox. I uploaded a fixed version to CRAN this afternoon.
 
Duncan Murdoch

Stéphane Laurent

unread,
Oct 14, 2013, 11:54:15 AM10/14/13
to shiny-...@googlegroups.com, Duncan Murdoch
Reply all
Reply to author
Forward
0 new messages