[IPython-dev] How-To create persistent, interactive UI elements outside cells

Matthias Bussonnier bussonniermatthias at gmail.com
Sat Nov 29 06:47:38 EST 2014


Hi, 

So back, from discussion. 
Le 28 nov. 2014 à 21:05, Hack-The-Paradise <sk.spiros at hotmail.com> a écrit :

> I think that you did not get my point.
> But lets get into the details when you or someone else manage to have enough
> time. To be honest i also do not have more time today.
> 
> For now, i would like to stress the title of the thread/topic and based on
> that & using the image example for having something more tangible to discuss
> i would like to ask again if you think that it's possible to achieve
> something similar (as the image) *without putting any code into the cells*
> of the Notebook. 

Yes, and what you want is a nbextension. 
I took the help_pannel example you link to and modified it to execute code in the kernel. 

https://gist.github.com/Carreau/682b52d75dacc5ab4fbb

the way js extension work, is you create a js file in ~/.ipython/nbextension/<yourproject/yourfile.js>
and specify that IPython need to load it (either in custom.js, rennet IPython master you can make that in a config file) 
the js file is executed when the notebook load. In the case of help_pannel it adds a button to the toolbar. 

In this JS file you can have access to the the JS object that communicate to the kernel, as well as the DOM to modifie HTML. 
In the modified example I link form, I generate a button, when you click, this button  as the kernel to execute "hi there", which basically just return a string. 

the Js handler receive thins truing and show it in the side panel. This does not use code in any cell the code is in the JS extension itself. In the example I only show how to handle execute request but you could hook-up anything like widgets... etc. 
You could also investigate user-expressions that can trigger code execution before user code. 


> 
> Goal: every time i open a notebook using a profile i want to see something
> like that (and interact with that) and yes i would like to use the existing
> base bricks (that's why i asked if there is something built in to use). 

Nb extension allow to share these extension in between profile, but yes you have to set a config option in the profile to activate the extension. 

Does that answer more your questions ? 

> 
> I will come back with more details and possible snippets of code.
> 
> 
> 
> 
> --
> View this message in context: http://python.6.x6.nabble.com/How-To-create-persistent-interactive-UI-elements-outside-cells-tp5079080p5079115.html
> Sent from the IPython - Development mailing list archive at Nabble.com.
> _______________________________________________
> 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/20141129/ff38f484/attachment.html>


More information about the IPython-dev mailing list