[IPython-dev] Best way to get the path to the static directory

Thorin Tabor tabor at broadinstitute.org
Wed Sep 30 15:37:28 EDT 2015

The extension is essentially a set of IPython widgets with some code to 
add a menu option to easily insert the widgets in a notebook. I have it 
working in IPython 3.2, and I'm trying to update it to Jupyter 4.

Here's how I currently have it working:

When the extension is loaded, I have code that checks for the necessary 
CSS and JS files, and then downloads them if they're not present. I do 
this through load_ipython_extension(). I then import them on the 
client-side using JQuery's $.getScript() for each of the files. One of 
the files contains the JavaScript code that adds the menu option.

I know that Jupyter 4 doesn't have profiles in the same way as IPython. 
I also know that the nbextension install mechanism you mentioned exists, 
but I don't know to (or if it is possible to) put downloaded files into 
it and serve them up to the client-side.

In Jupyter 4, I don't know to which directory it would be best to 
download the JS files. As mentioned, in IPython 3.2 this worked by 
downloading the files to the /static directory of the user's IPython 
profile, and then the notebook server would serve them up so that I 
could import them on the client-side using $.getScript(). This was nice 
because someone can install the extension through PIP, and then the 
extension puts all the necessary client-side stuff in place for the user 
when it's first executed. The user doesn't need to worry about any code 
beyond %load_ext.

Maybe the better question is: I want to serve up and execute an 
arbitrary number of JavaScript files in the notebook when our Python 
extension is loaded. What is the best way to do that?


On 9/10/15 16:06, MinRK wrote:
> From a Python API, |custom.{js|css}| live in 
> |jupyter_core.paths.jupyter_config_dir() + '/custom'|. Note that you 
> probably shouldn’t be putting any files in there - if you are writing 
> javascript extensions, they should be placed in nbextensions via
> |jupyter nbextension install (4.x) or ipython install-nbextension (3.x) |
> -MinRK
> On Thu, Sep 10, 2015 at 9:05 PM, Thorin Tabor 
> <tabor at broadinstitute.org <mailto:tabor at broadinstitute.org>> wrote:
>     When writing a Jupyter notebook extension for Jupyter 4, what is
>     the recommended way to get the path to the static directory (you
>     know, the one where custom.js and custom.css are being served from)?
>     In Jupyter 3.x, you used to be able to reference...
>         IPython.utils.path.locate_profile() + '/static'
>     ...but that no longer seems to suffice. I know that...
>         notebook.notebookapp.DEFAULT_STATIC_FILES_PATH
>     looks like it might work, but it seems like there ought to be a
>     better way. Does anyone have a recommendation?
>     Thorin
>     _______________________________________________
>     IPython-dev mailing list
>     IPython-dev at scipy.org <mailto:IPython-dev at scipy.org>
>     http://mail.scipy.org/mailman/listinfo/ipython-dev
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150930/35f6f286/attachment.html>

More information about the IPython-dev mailing list