[IPython-dev] Loading nbextension on widget instantiation
Nicholas Bollweg
nick.bollweg at gmail.com
Tue Jun 17 09:37:21 EDT 2014
We have also encountered this issue: we have, for the moment, dealt with it
with a mixin for our python-side widget classes that does a require against
the _view_name:
from IPython.display import display, Javascript
> import time
>
> js_path = "/nbextensions/ipynbdbtk/js"
>
> class ViewLoaderMixin(object):
> def __init__(self, *args, **kwargs):
> script = """require(['%(path)s/%(view)s.js'], function(){
> console.log('%(view)s loaded');
> });""" % {
> "path": js_path,
> "view": self._view_name
> }
> display(Javascript(script))
> super(ViewLoaderMixin, self).__init__(*args, **kwargs)
>
I think this is equivalent to your solution (didn't know about
load_extensions: that would make it more terse).
I second being able to document the location of the file, but don't know
enough about the specifics to have an opinion on the approach.
Speaking of documentation: a template for building extensions with widgets
that that embodied the baseline of knowledge spread all over the community
would be great. I have used paste before, which seems kind of heavy these
days. Cookiecutter looks good:
> https://github.com/audreyr/cookiecutter#available-cookiecutters
>
or yeoman:
> http://yeoman.io/
Yeoman may actually be preferable, in that one would be more inclined to
use good front-end practices like bower, less/sass, linitng, etc. even
while developing for python.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140617/9530a6dc/attachment.html>
More information about the IPython-dev
mailing list