[IPython-dev] loading a static JS file when loading an IPython extension in the notebook

Nicholas Bollweg nick.bollweg at gmail.com
Fri Jul 11 09:38:32 EDT 2014


Here's the most recent thread on that:
http://python.6.x6.nabble.com/Loading-nbextension-on-widget-instantiation-tt5060760.html#none

I captured some of the pattens into a cookiecutter template:
https://github.com/bollwyvl/cookiecutter-ipython-widget

You can use this pattern, even if you aren't using widgets, though.

The key chores are:

   - make sure your static files, in a folder, get copied on install
   (MANIFEST.in)
   - when you are ready to use your JS, copy static into the
nbextensions directory
   (in the users profile) with IPython.html.nbextensions.install_nbextension
   - display them (and/or any css) with display


Here is the file I use for encapsulating those steps:
https://github.com/bollwyvl/cookiecutter-ipython-widget/blob/master/%7B%7Bcookiecutter.repo_name%7D%7D/%7B%7Bcookiecutter.pkg_name%7D%7D/widgets/mixins.py
It gets called each time an instance of a class is instantiated. It was
suggested that this is preferable over loading it at import time.

Hope this helps!


On Thu, Jul 10, 2014 at 8:48 AM, Cyrille Rossant <cyrille.rossant at gmail.com>
wrote:

> Hi,
>
> What is the best way to write an IPython extension such that
> `%load_ext myext` loads `myscript.js` in the current notebook? If
> possible, I'd prefer to avoid asking users to make manual changes to
> custom.js or similar.
>
> Thanks,
> Cyrille
> _______________________________________________
> 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/20140711/6fb2fc09/attachment.html>


More information about the IPython-dev mailing list