dmurdoch/rgl

rglwidget no longer renders in Jupyter

rahuntsinger opened this issue · 12 comments

  • rgl Version: 1.0.1
  • R Version: 4.2.1 (64-bit)
  • Platform: Windows 11

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)

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

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.

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()

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.

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

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.

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.

Cool.

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.

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")

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