sending RGL output to Shiny (non-interactively)

865 views
Skip to first unread message

Luca Fenu

unread,
Mar 4, 2013, 8:26:47 AM3/4/13
to shiny-...@googlegroups.com
Hi all,

I've been playing with rgl within shiny, and even though I'd like ultimately to implement something analogous to the webGL parser function Jeff Allen has shared in a previous post, right now I'd be more than happy of just printing out the plot generated and let the user download it through a link. Also, this setup is more amenable to batch programs where I have already setup an optimal visual orientation, and do not need interactivity to adjust/explore. 

However, rgl doesn't return the plot the same way other graphics systems do, hence can't insert the code in a downloadHandler() call.

I thought I'd save the plot as a png using rgl.snapshot and show it to the user as part of the UI, if nothing else. However, I am not sure of how to do that, either. I understand this should be possible since reactivePlot itself returns a png to the UI for presentation. 

Any suggestion?

Cheers,

Luca

Winston Chang

unread,
Mar 4, 2013, 11:58:55 AM3/4/13
to shiny-...@googlegroups.com
Hi Luca -

Right now there's not a simply way to send arbitrary .png files to the browser. renderPlot() only works with code that can be wrapped in `png(); ... ; dev.off()`, and it will send the output to the client. There have been a few questions on the mailing list which could use this capability, though, so it's something we'll think about adding.

-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.
 
 

Andrew Defries

unread,
May 7, 2013, 4:23:53 PM5/7/13
to shiny-...@googlegroups.com
Dear Winston,

Could you clarify your post.

I'm trying to make a shiny app with library(rgl), but cannot get past an error for rgl.open():

rgl.open() failed

Also, in a normal R session I get an RGL error.

> library(rgl)
Warning messages:
1: In rgl.init(initValue) : RGL: unable to open X11 display
2: In fun(libname, pkgname) : error in rgl_init



I saw here how to change configurations, but don't have sudo on spark.

http://www.r-bloggers.com/graphical-tools-rgl-on-a-headless-shiny-server/

Winston Chang

unread,
May 7, 2013, 8:02:13 PM5/7/13
to shiny-...@googlegroups.com
Oh, hm, I didn't realize that rgl needs to have a running X device to even load the package.

Using the instructions in Jeff's blog post is probably not a good idea for multi-user systems like glimmer (and our new server, spark) -- it's probably a security hole to have a single X session for the shiny-server process that is used by all apps.

It's possible for each user to start a Xvfb (X virtual frame buffer) device, but this could lead to other problems. There's no guarantee that Xvfb will be closed properly when an app is closed, and this could lead to many, many running X sessions on glimmer, especially since there are so many users.

I'll look into this a bit more to see if there's a better way to use rgl on multi-user system like glimmer and spark.

-Winston

Winston Chang

unread,
May 14, 2013, 1:00:22 PM5/14/13
to shiny-...@googlegroups.com
Hi everyone -

We've looked into setting up rgl on our hosted servers glimmer and spark, but haven't found a good secure way of making it work in a multi-user environment. Unfortunately, this means that apps that use rgl won't be able to run on these servers.

-Winston

Jon P

unread,
May 14, 2013, 1:54:11 PM5/14/13
to shiny-...@googlegroups.com
Hi Winston,
 
Does this apply to other interactive plotting techniques, as well? Specifically, I'm thinking of the indentify() function (in the graphics library)
 
Thanks for all the work,
Jon

Winston Chang

unread,
May 14, 2013, 2:32:18 PM5/14/13
to shiny-...@googlegroups.com
Sorry, identify() won't work, since it needs to talk directly to the graphic device, but Shiny apps show the plots through the browser. I know this doesn't help now, but the future of interactive graphics with Shiny for the graphics to be rendered in the browser, which will make it possible to do things like that.

-Winston

Duncan Murdoch

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


On Tuesday, May 7, 2013 8:02:13 PM UTC-4, Winston Chang wrote:
Oh, hm, I didn't realize that rgl needs to have a running X device to even load the package.


 
Stéphane Laurent pointed out this thread to me.  Currently rgl does need a display in order to do anything; that's a legacy from the time when there was no way to get anything out of it without one.  Nowadays with writeWebGL(), other writeXXX() functions, and rgl.attrib(),
you might be able to do useful work without a display. I'll look into adding a display-free device.

Yuan Yuan

unread,
Jul 5, 2013, 4:11:08 PM7/5/13
to shiny-...@googlegroups.com
If showing png to the UI is your question, then here is my solution:

1. Make main_panel a uiOutput that's dynamically created in server.R instead of defining it in ui.R.
2. save png plots to tempdir() and in ui.R, call addResourcePath('plots', tempdir())
3. When generating the main_panel, insert the plots using path as 'plots/[your_plot_file_name.png]'.

In the "Model" tab, choose some X's as predictors, and click "Run". You'll see some png's added to a tab in the main panel.

Joe Cheng

unread,
Jul 5, 2013, 9:01:41 PM7/5/13
to shiny-...@googlegroups.com
Duncan, that would be amazing. There is a ton of potential here for tighter rgl and Shiny integration.

Yuan, rulefit+ is cool, I really like the dynamic tabs! Glad you were able to figure that one out!


--

Duncan Murdoch

unread,
Jul 17, 2013, 10:05:13 PM7/17/13
to shiny-...@googlegroups.com
I've just uploaded a patch to rgl to R-forge that lets it run without any active display.  Set options(rgl.useNULL=TRUE) (or set the RGL_USE_NULL environment variable to "true") before loading rgl, and it will not need a display.

The assumption of an active display was fairly widespread in the code, so there may be some spots I missed.  (And it's hard to spot errors in graphics code that doesn't display anything!) 

There are a few limitations:  it won't update the modelMatrix or projMatrix components of par3d(), for example, and there's no frame buffer, so nothing involving reading pixels is available.  But it does run through its usual tests without crashing, and will produce WebGL output.

Duncan

Joe Cheng

unread,
Jul 18, 2013, 2:44:44 AM7/18/13
to shiny-...@googlegroups.com
Awesome! Thanks Duncan, can't wait to play with this!
--
Sent from my phone

Stéphane Laurent

unread,
Oct 14, 2013, 11:56:01 AM10/14/13
to shiny-...@googlegroups.com

Luca Fenu

unread,
Oct 14, 2013, 1:18:38 PM10/14/13
to Stéphane Laurent, shiny-...@googlegroups.com
awesome! Thank you trestletech!


On 14 October 2013 16:56, Stéphane Laurent <lauren...@yahoo.fr> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/SC6M8NfUKDI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

Andrew Defries

unread,
Oct 16, 2013, 4:26:52 PM10/16/13
to shiny-...@googlegroups.com, luca...@gmail.com

Dear RShiny users,

I downloaded the shinyRGL and installed on the spark server. I'm getting the error

Error: rgl.open failed

see here:

http://spark.rstudio.com/adefries/AcetyleneActives/

Any advice is appreciated.


##############################
#ui.R fragment

tabsetPanel(
   tabPanel("shiny RGL visualization", webGLOutput("myWebGL"))

#server.R fragment
shinyServer(function(input,output){
############# 
output$myWebGL <- renderWebGL({
    points3d(1:10, 1:10, 1:10)
    axes3d()
 })
#############
)}

Duncan Murdoch

unread,
Oct 16, 2013, 4:41:06 PM10/16/13
to Andrew Defries, shiny-...@googlegroups.com, luca...@gmail.com
On 13-10-16 4:26 PM, Andrew Defries wrote:
>
> Dear RShiny users,
>
> I downloaded the shinyRGL and installed on the spark server. I'm getting
> the error
>
> Error: rgl.open failed
>
> see here:
>
> http://spark.rstudio.com/adefries/AcetyleneActives/
>
> Any advice is appreciated.

You probably haven't set up an X11 server for it. Without that, you
need to follow the instructions for a "headless server" in the package
README. (Not sure why that isn't a vignette, but the package is new.)

Duncan Murdoch

>
>
> ##############################
> #ui.R fragment
>
> tabsetPanel(
> tabPanel("shiny RGL visualization", webGLOutput("myWebGL"))
>
> #server.R fragment
> shinyServer(function(input,output){
> #############
> output$myWebGL <- renderWebGL({
> points3d(1:10, 1:10, 1:10)
> axes3d()
> })
> #############
> )}
>
>
>
> On Monday, October 14, 2013 10:18:38 AM UTC-7, Luca Fenu wrote:
>
> awesome! Thank you trestletech!
>
>
> On 14 October 2013 16:56, St�phane Laurent <lauren...@yahoo.fr> wrote:
>
> ShinyRGL package !!!
> http://trestletechnology.net/2013/10/interactive-3d-in-shiny-shinyrgl/
> <http://trestletechnology.net/2013/10/interactive-3d-in-shiny-shinyrgl/>
>
>
>
> --
> You received this message because you are subscribed to a topic
> in the Google Groups "Shiny - Web Framework for R" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/shiny-discuss/SC6M8NfUKDI/unsubscribe
> <https://groups.google.com/d/topic/shiny-discuss/SC6M8NfUKDI/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email
> to shiny-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
Reply all
Reply to author
Forward
0 new messages