Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: offline=True kwarg in embed_html was failing to save dependency jupyter-threejs.js #198

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

GenevieveBuckley
Copy link
Contributor

This PR adds a function save_jupyterthreejs to embed.py to download and save the jupyter-threejs.js dependency required for offline viewing of ipyvolume html files.

Closes #192

The offline=True kwarg in ipyvolume.embed.embed_html() has been failing to save the file at https://unpkg.com/jupyter-threejs@2.0.1/dist/index.js locally as js/jupyter-threejs.js
Copying that file manually into js/jupyter-threejs.js fixes the issue and allows offline viewing.

Copy link
Collaborator

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, indeed, this was missing. I need to talk to @vidartf about how to get the right threejs version, so I'll get back to you. Many thanks already!

__version_threejs__ = '2.0.1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

threejs is at version 98 btw: https://threejs.org/
pythreejs is what you meant, I know, it is confusing.
I'll talk with @vidartf about it, how we can get the right threejs version that matches the pythreejs one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I've updated the variable name to be clearer: __version_pythreejs__. The actual __version_threejs__ never got used (the master branch has some stuff commented out) so I haven't included that in _version.py

Yes, it would be good to know what you and @vidartf decide is the best way to keep threejs/pythreejs in sync.

@maartenbreddels
Copy link
Collaborator

As it is now, threejs is embeded in jupyter-threejs's embed.js, although it shouldn't, and it is actually configured using require's path in https://github.com/jupyter-widgets/pythreejs/blob/master/js/src/embed.js
@vidartf 's plan is to test making threejs external, exposing the semver version in the Python package, and then we know if it works.
Also, ipyvolume should do the same, make the threejs external, and copy the config of https://github.com/jupyter-widgets/pythreejs/blob/master/js/src/embed.js

@GenevieveBuckley it might be that the PR as it is now is working, can you confirm that? ipyvolume and jupyter-threejs have their own version of threejs, which is non-ideal, but if it works, it works.

@GenevieveBuckley
Copy link
Contributor Author

Yes, I can confirm that it works for these circumstances:

python version 3.6.6
jupyter notebook 5.7.0
ipywidgets version 7.4.2
ipyvolume developmernt installation 0.5.2-dev.1

I tested using this code while connected to the internet (writing to file won't work if you're not connected):

import numpy as np
import ipyvolume as ipv

y = np.random.randn(1000)
x = np.random.randn(1000)
z = np.random.randn(1000)

fig = ipv.figure()
ipv.scatter(x, y, z)
ipv.embed.embed_html('offline_test.html', fig, offline=True, devmode=True)

Once offline, reading the file is successful across all browsers I have available:

  • Chrome version 70.0.3538.77 (Official Build) (64-bit)
  • Firefox version 63.0.1 (64-bit)
  • Safari version 12.0.1 (14606.2.104.1.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

offline=True in embed_html failing to save required file js/jupyter-threejs.js
2 participants