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

Matthias BUSSONNIER bussonniermatthias at gmail.com
Thu Dec 4 05:58:55 EST 2014


Hi, 

Le 4 déc. 2014 à 00:50, Hack-The-Paradise a écrit :

> Thank you but this is not in the direction that my team and i are going...
> 
> I think it's in beta, probably abandoned and it's best case scenario is
> this:
> https://github.com/ipython-contrib/IPython-notebook-extensions/wiki/hide_input_all

This still forces you to ass code in cells input. 

> As i explicitly described we aim to communicate with the kernel in order to
> achieve what we want, maybe hiding specific cells would be an alternative
> but it seems very primitive one…

You might not have received my previous mail, so here is the archive version:

	

In it I gave you an example on how to load custom javascript in each notebook 
loaded from a specific server. As well as the ability to communicate with the kernel. 



> I thought that this would be a lively topic but it also seems that the Devs
> are not interested…

Did you investigate the user-expressions as I suggested you to ? It allows you to execute code just before/after
user code. 

Did you even achieved to get a side panel which is capable of executing 1+1 ? 
If you are not even there, the rest will not make much sense. 


As you now know how to execute your own string of code in the kernel, you are aware that you are actually sending a message
with registered callback.

You can also manually rester a callback for a specify message with `kernel.set_callback_for_message`.

In particular if you are not especially running from from a cell, manner.js:111-135 expect you to define the `iopub.get_cell` callback
(name might be unfortunate but is mostly returning cells-like object) that provide , in a nested propertyy a dom element.

You can get convinced of that by exec :

> IPython.notebook.get_selected_cell().widget_subarea

That return the Dom element of widgets.

"Just" define now the dom element in which you want your widget.


Here is another starting point that should move you closer to your goal. 


%%html
<div id='xxx'></div>
<div id='yyy'></div>

%%javascript
IPython.notebook.kernel.execute(
        'from IPython.html.widgets import interact\n'+
        '@interact\n'+
        'def fun(n=1):\n'+
        '    print(n)\n',     
          {
                shell : {
                  reply : function(data){console.log('reply',data.content)},
                  payload : {
                    set_next_input : function(data){console.log('sni',data)},
                    page : function(data){console.log('page',data)},
                  }
                },
                iopub : {
                    output : function(data){$("#yyy").append((data.content.data||{'text/plain':'text/plain'})['text/plain']); console.log('output',data.content)},
                    clear_output : function(data){console.log('cloup',data)},
                    get_cell: function(data){console.warn('got celllllll1111111!!!!'); return {widget_subarea:$('#xxx')}}
                    
                },
                input : function(data){console.log('rawin',data)}
          }
        , {silent: false, store_history: true})


It will at least I've you a slider in a custom div.
You will still have to hook up the custom update triggered by the changing value of the slider. 

Still I'm still not sure what you did as you don't safe code example beyond notebook.
and I'm not sure of what you want to achieve : 
	- display the same tools in a sidebar for all notebook. 
	- display tools that depends on which notebook are loaded in a sidebar.

-- 
M


> P.S.: I also found:
> https://github.com/ipython-contrib/IPython-notebook-extensions/tree/master/testing/hierarchical_collapse
> But i have not dig into to it yet...
> 
> Any thoughts would be really appreciated...
> 
> 
> 
> --
> View this message in context: http://python.6.x6.nabble.com/How-To-create-persistent-interactive-UI-elements-outside-cells-tp5079080p5079576.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




More information about the IPython-dev mailing list