ngl icon indicating copy to clipboard operation
ngl copied to clipboard

Embedding NGL 2.2.2 (via `nglview`) doesn't work anymore

Open hainm opened this issue 1 year ago • 9 comments

It's hard to describe this issue but I will try my best.

Basically nglview uses this chunk of codes to generate the embeddable HTML: https://github.com/nglviewer/nglview/blob/98d7df9c5b2c035278724eacfb8184631c17015b/js/webpack.config.js#L48-L73

Something like below (in juypter notebook):

# 1st cell
import nglview as nv
view = nv.demo()
view

# 2nd cell
nv.write_html("index.html", view)
!open index.html

Upgrading from NGL 2.0.0-dev.39 to 2.2.2 make the embedding stop working. Below is the error:

image

I originally thought it was an issue with ipywidgets (https://github.com/jupyter-widgets/ipywidgets/issues/3878), but I've tried to switch back to NGL 2.0.0-dev.39 with the same ipywidgets version and thing still works properly.

Can you please have a look. Thanks

Hai

hainm avatar Jan 17 '24 04:01 hainm

Oh, NGL 2.2.2 works fine with the jupyter notebook and lab (via nglview). It's just the HTML exporting doesn't work.

hainm avatar Jan 17 '24 04:01 hainm

The latest "working" version is 2.1.1

image

hainm avatar Jan 17 '24 04:01 hainm

@hainm a view of the line that fails within the source code would be very useful, or a way to reproduce it (a live version somewhere?) Between 2.1.1 and 2.2.0 the bundling has changed. It's possible that's the cause of this bug

papillot avatar Jan 19 '24 20:01 papillot

@hainm a view of the line that fails within the source code would be very useful, or a way to reproduce it (a live version somewhere?) Between 2.1.1 and 2.2.0 the bundling has changed. It's possible that's the cause of this bug

Dear @papillot

Please download (and rename) this file: https://github.com/jupyter-widgets/ipywidgets/files/13894919/index.html.txt

hainm avatar Jan 19 '24 20:01 hainm

Thanks for this. I did a first pass at investigating this last week. This is related to a change in the bundling system. The esm module that is loaded in this case, contains mangled names for Three.js dependency constants. Mangling is fine when Three.js is part of the bundle (that is the case with the "regular" .min.js bundle). I am not sure it makes sense in the case of esm.

ppillot avatar Jan 27 '24 15:01 ppillot

Dear @ppillot,

do you have a solution yet? If not, is it possible to follow the old way that works?

hainm avatar Mar 04 '24 01:03 hainm

For various reasons, I haven't made any progress on this. I did investigate further and noticed that the previous code also had mangled identifiers.

papillot avatar Mar 04 '24 02:03 papillot

thanks for the update.

hainm avatar Mar 04 '24 14:03 hainm

It seems to me that upgrading to latest NGL (in this thread) will prevent nglview from being displayed in VSCode too: https://github.com/microsoft/vscode-jupyter/issues/15757#issuecomment-2229768924

User reported that nglview 3.0.8 works fine but the subsequent versions do not work. We introduce new NGL after 3.0.8 image

hainm avatar Jul 16 '24 16:07 hainm