[IPython-dev] Loading nbextension on widget instantiation

Andrew Gibiansky andrew.gibiansky at gmail.com
Tue Jun 17 11:43:52 EDT 2014


I'm not sure, but this *sorta* looks like the same issue I raised in the
thread titled "Javascript ordering semantics". Here's the solution I found
then:

After digging around in the frontend JS source for a while, I found a
> solution. Instead of sending a display_data with mimetype text/html and an
> embedded script tag, just send two display_data messages, one with mimetype
> application/javascript (with required JS) which must be executed before the
> comm_open and another with mimetype text/html (with required HTML to be
> inserted, if any).
>
> This fixes the issue I have. However, it's still a bit strange that Chrome
> and FF do the original thing differently, but looks like there's an easy
> workaround.
>

Apologies if this is actually a completely different issue under the hood.



On Tue, Jun 17, 2014 at 6:37 AM, Nicholas Bollweg <nick.bollweg at gmail.com>
wrote:

> 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.
>
> _______________________________________________
> 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/20140617/58dc6399/attachment.html>


More information about the IPython-dev mailing list