Polymake.jl icon indicating copy to clipboard operation
Polymake.jl copied to clipboard

visual() / threejs issue with Jupyter Lab

Open vukk opened this issue 4 years ago • 4 comments

The following bug seems to be present when using Jupyter Lab notebooks: Writing

using Polymake;
p2 = @pm polytope.Polytope{}(POINTS=[1 -1 -1; 1 1 -1; 1 -1 1; 1 1 1; 1 0 0], INPUT_LINEALITY=[0 1 0])
visual(p2)

results in Uncaught ReferenceError: requirejs is not defined in the web console.

Similar issues in other packages, reported elsewhere:

  • https://discourse.jupyter.org/t/requirejs-bug-in-jupyterlab/5518/3
  • https://root-forum.cern.ch/t/jsroot-requirejs-issue-in-jupyterlab/40900

Version information: JupyterLab Version 3.0.5 Julia 1.5.3 Polymake.jl 0.5.5 Polymake.version() -> v"4.3.0"

Workaround: ThreeJS works in a classic notebook. Open your notebook as a classic notebook in Jupyter Lab via Help -> Launch Classic Notebook.

vukk avatar Jan 15 '21 19:01 vukk

@vukk thanks for reporting, but reading the discourse thread I couldn't understand what is the underlying problem and if there is something we could do about. Will the issue be resolved in jupyterlab (i.e. upstream?)


As a sidenote you can use

using Polymake
p2 = polytope.Polytope(POINTS=[1 -1 -1; 1 1 -1; 1 -1 1; 1 1 1; 1 0 0], INPUT_LINEALITY=[0 1 0])
visual(p2)

without macro magic ;)

kalmarek avatar Jan 16 '21 12:01 kalmarek

The underlying problem is that the normal jupyter interface has RequireJS loaded and we use that to load three.js from within the notebook. But jupyterlab does not have requirejs active and I don't think this will change, it seems to be a different design that we are not compatible with right now. There does seem to be a pythreejs package that can also be installed for jupyterlab, but that seems rather complicated from a user-perspective in comparison to just running the visual command ....

Maybe you could try installing jupyter-require ? But I don't know if this needs any extra stuff in the notebook to make it work. Edit: or maybe jupyterlab_requirejs since the jupyter-require repo is archived ...

benlorenz avatar Jan 16 '21 13:01 benlorenz

The underlying problem is that the normal jupyter interface has RequireJS loaded and we use that to load three.js from within the notebook. But jupyterlab does not have requirejs active and I don't think this will change, it seems to be a different design that we are not compatible with right now.

This is correct. I'd add that the JupyterLab documentation states:

JupyterLab will eventually replace the classic Jupyter Notebook. Throughout this transition, the same notebook document format will be supported by both the classic Notebook and JupyterLab.

The pythreejs package seems to be more for writing custom javascript into your notebook for visualization.

I'm not sure if it is possible right now for you, and how they work within jupyter, but in the long run I'd look into trying to use native ES6 imports

  • https://caniuse.com/es6-module-dynamic-import
  • https://caniuse.com/es6-module

If I was working in frontend/fullstack right now, I'd try to fix this myself. However, I'm unfortunately a bit out of practice and currently deep in the thesis swamp :)

vukk avatar Jan 16 '21 22:01 vukk

Thanks a lot for the input, we will try look into this but it might take a bit.

If I remember correctly we had plenty of problems getting this to work at all when we started this (and then never really touched it because it was working), but probably things are somewhat better now. At least it looks like the threejs examples that we need are available as modules now.

benlorenz avatar Jan 16 '21 22:01 benlorenz