dmurdoch / rgl

rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
https://dmurdoch.github.io/rgl/
GNU General Public License v2.0
85 stars 20 forks source link

rglwidget no longer renders in Jupyter #329

Closed rahuntsinger closed 1 year ago

rahuntsinger commented 1 year ago

Help! rglwidget no longer renders in Jupyter. In rgl versions 0.108.3 and earlier, it works fine. In rgl versions 0.109.2 and later, it displays a blank image (of the correct size). Here is a sample of code that used to work and now does not work:

options(rgl.useNULL=TRUE) open3d(silent=TRUE) view3d(theta=-20, phi=-3, fov=30, zoom=0.85) plot3d(data, type="s", col=PALETTE[1], xlim=c(0,10), ylim=c(0,10), zlim=c(0,10)) spheres3d(data.frame(x1=new$x1, x2=new$x2, outcome=0:10), radius=0.35, color=NEW_COLOR, add=TRUE) grid3d(c("x","y","z")) rglwidget(width=270, height=270)

dmurdoch commented 1 year ago

It renders fine in browsers, so this looks like a Jupyter issue. You should report it there.

dmurdoch commented 1 year ago

Are you seeing leaflet displays working? e.g.

library(leaflet)
leaflet() %>% addTiles()

In R, this displays a world map. In a test Jupyter notebook, it displays nothing. rgl uses the same methods as leaflet for display.

rahuntsinger commented 1 year ago

In was hoping you could identify what changed in 0.108.3 to 0.109.2 that could have caused this issue, and perhaps suggest a workaround. Many of us rely on rgl for interactive graphics in our Jupyter notebooks, but are forced to use 0.108.3 without any of the later enhancements.

Here's what happening with Jupyter and rgl 1.0.1 ...

This displays fine: library(leaflet) leaflet() %>% addTiles()

This displays fine in non-interactive mode: options(rgl.useNULL=TRUE) open3d(silent=TRUE) plot3d(data.frame(x=1:10, y=1:10, z=1:10)) display_jpeg(file = rglwidget(snapshot=TRUE))

This displays a blank window: options(rgl.useNULL=TRUE) open3d(silent=TRUE) plot3d(data.frame(x=1:10, y=1:10, z=1:10)) rglwidget()

dmurdoch commented 1 year ago

I don't get any display when I try the leaflet code. If you can tell me how to set up Jupyter so that works, I'll probably be able to see why rgl doesn't. Here's what I've done:

Installed jupyter using

pip install jupyterlab
pip install notebook
pip install r-irkernel

Started it using

jupyter notebook

and then chose to open an R notebook. In that notebook, I run the leaflet code or the rgl code and see no display from either one.

rahuntsinger commented 1 year ago

Here attached is screen shot of a test Jupyter notebook with outputs. Note that upper-right corner button must be set to Trusted to enable interactive displays.

Here also attached are my notes on installing Jupyter and R. (You can skip over most of the Python install stuff.)

Or, if more convenient for you, I can provide you access to my https://rah.haas.berkeley.edu Jupyter environment already setup to run and edit the test notebook there. Just let me know where to securely send you login credentials.

Really appreciate your attention to this issue. Thanks.

Screenshot 2023-03-10 111750 NOTES Install.docx

dmurdoch commented 1 year ago

I'm not using Windows, but I tried to pick out appropriate parts of your install instructions to use on my Mac. Still, I don't have enough of the right stuff installed to get either the leaflet display or the blank rgl display.

I've written to the IRDisplay maintainer to ask for help.

Regarding login credentials: I'll try that if you want, but I'm not sure what level of security you need to send them to me. You could email them to the email address listed as rgl maintainer; that goes to me. But it's a Gmail address, so there's a risk someone else can read my mail.

dmurdoch commented 1 year ago

Okay, I finally got leaflet going. (The key was to use Chrome as the browser; nothing would display in Firefox.) Then I could see the error that was occurring when it was trying to display rgl -- it was failing when it tried to load the shaders that are used in WebGL. This should be fixable, I just need to look into some details.

rahuntsinger commented 1 year ago

Cool.

dmurdoch commented 1 year ago

This may be fixed now. The problem is that repr.htmlwidget ignored items put in the page header, and that's where rgl was putting the shaders. I've now put them elsewhere, and it works for me. I've merged the change into the master branch; please test rgl 1.0.15 or higher. There may be other issues, but I can't think of anything closely related.

rahuntsinger commented 1 year ago

Wow, that was a quick resolution! rgl development version 1.0.15 displays rgl widgets in Jupyter just fine. Love the rgl package. Many thanks.

When do you expect the fix will be available via install.packages() from CRAN? Meanwhile, FYI to other Jupyter users, you can get the fix like this: remotes::install_github("dmurdoch/rgl")

dmurdoch commented 1 year ago

v1.1.3 has just been accepted by CRAN. It contains this fix.

rahuntsinger commented 1 year ago

Wonderful! Thanks so much.

RICHARD HUNTSINGER

408-219-6301 | @.> @. | www.huntsinger.com

From: dmurdoch @.> Sent: Sunday, March 26, 2023 4:38 PM To: dmurdoch/rgl @.> Cc: Richard Huntsinger @.>; Author @.> Subject: Re: [dmurdoch/rgl] rglwidget no longer renders in Jupyter (Issue #329)

v1.1.3 has just been accepted by CRAN. It contains this fix.

— Reply to this email directly, view it on GitHub https://github.com/dmurdoch/rgl/issues/329#issuecomment-1484274040 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AKAY55OQQLEUNFKUUW3KWQTW6DHNFANCNFSM6AAAAAAVVS7CQE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AKAY55KLFTTOVB6EXAW6R3LW6DHNFA5CNFSM6AAAAAAVVS7CQGWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSYPA4XQ.gif Message ID: @. @.> >