The module "vpython" includes a JavaScript component for displaying 3D 
animations in a notebook. The JavaScript code has to read some data files 
which are jpegs used as textures on 3D objects and font files from which 
character contours are extracted and used to display extruded 3D text. When 
connected to the internet these files can be read from copies at Amazon Web 
Services, but when off-line they need to be read from local disk storage. 
Both the JavaScript programs and these data files are in nbextensions, in a 
progam folder and a data folder. 

What I need to do in a JavaScript program is to reference "../data/a.jpeg" 
or "../data/b.ttf", but this doesn't work, because relative file references 
are based on "localhost:8888/notebooks/my_notebook_directory" and so the 
file reference fails, since the place where I store my notebooks is 
unrelated to the location of nbextensions.

A colleague showed me how to obtain an absolute address, which I could use 
to reference the data files:

from jupyter_core.paths import jupyter_data_dir
Image(filename=jupyter_data_dir() + "/nbextensions/images.png")

This scheme works for a displaying an image but if I try to read data into 
a JavaScript program using an absolute address I get a CORS error 
(Cross-Origin Resource Sharing), and it would seem to be exceptionally 
challenging to get around this restriction. I tried the experiment of 
putting the data files next to my own notebooks, and the relative 
addressing works, but this is not a general solution for the vpython module.

Is there some way to reference data in nbextensions yet not have this count 
as a cross-reference error? Or can someone think of some other approach 
that could work? This seems important, because one often needs to be able 
to work off-line, say on an airplane.

Bruce

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jupyter+unsubscr...@googlegroups.com.
To post to this group, send email to jupyter@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/de4ebb1c-f47a-45f6-b9f4-be4723571dc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to