<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 10 July 2014 07:48, Cyrille Rossant <span dir="ltr"><<a href="mailto:cyrille.rossant@gmail.com" target="_blank">cyrille.rossant@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id=":1id" class="" style="overflow:hidden">What is the best way to write an IPython extension such that<br>


`%load_ext myext` loads `myscript.js` in the current notebook? If<br>
possible, I'd prefer to avoid asking users to make manual changes to<br>
custom.js or similar.</div></blockquote></div><br></div><div class="gmail_extra">We are going to come up with a mechanism for installing and using notebook extensions that doesn't depend on IPython kernel-side extensions, because it should be independent of the kernel language. So for pure JS extensions, I'd rather get that sorted out than have hacks to load them from Python.<br>

<br></div><div class="gmail_extra">However, there is a need for code which has both a Python component and a JS piece. In that case, you can load the JS by doing something like this:<br><br><div class="" id="LC13"><span class="">pkgdir</span> <span class="">=</span> <span class="">os</span><span class="">.</span><span class="">path</span><span class="">.</span><span class="">dirname</span><span class="">(</span><span class="">__file__</span><span class="">)</span><br>

<span class="">nbextensions</span><span class="">.</span><span class="">install_nbextension</span><span class="">([</span><span class="">os</span><span class="">.</span><span class="">path</span><span class="">.</span><span class="">join</span><span class="">(</span><span class="">pkgdir</span><span class="">,</span> <span class="">'myjsdir'</span><span class="">)],</span> <span class="">symlink</span><span class="">=</span><span class="">True</span><span class="">)</span></div>

<div class="" id="LC14"><span class="">display</span><span class="">(</span><span class="">Javascript</span><span class="">(</span><span class="">"IPython.load_extensions('myjsdir/somefile');"</span><span class="">))<br>

<br></span></div><div class="" id="LC14"><span class="">This is what I do in mobilechelonian: <a href="https://github.com/takluyver/mobilechelonian/blob/master/mobilechelonian/__init__.py">https://github.com/takluyver/mobilechelonian/blob/master/mobilechelonian/__init__.py</a></span><br>

<div class="" id="LC14"><span class=""><br></span></div><div class="" id="LC14"><span class="">We are also going to build a mechanism to allow widgets to specify the file where their JS part is contained, which will be loaded with requirejs, which will make this unnecessary in many cases.<br>

<br></span></div><div class="" id="LC14"><span class="">Thomas<br></span></div><br></div><br></div></div>