Interactivity

First we import some functions from IPython.html.widgets and IPython.display


In [ ]:
from IPython.html.widgets import interact, interactive, fixed # new in IPython3: interactive_manual
from IPython.html import widgets
from IPython.display import clear_output, display, HTML

A function to demonstrate interactivity, that simply prints a HTML table of the keyword arguments passed into the function


In [ ]:
def show_args(**kwargs):
    keys = sorted(kwargs.keys())
    s = '<h3>Arguments:</h3><table>\n'
    for k in keys:
        v = kwargs[k]
        s += '<tr><td>{0}</td><td>{1}</td></tr>\n'.format(k,v)
    s += '</table>'
    display(HTML(s))

In [ ]:
show_args(Current=2.6, Text="Hello world!", z=True, Temp=4, Algorithm='This', a=0.5)

Now we wrap this in a call to interact


In [ ]:
i = interact(show_args,
         Temp=(0,10),
         Current=(0.,10.,0.01),
         z=True,
         Text=u'Type here!',
         Algorithm=['This','That','Other'],
         a=widgets.FloatSliderWidget(min=-10.0, max=10.0, step=0.1, value=5.0)
         )

Problem: reloading the cell resets the values picked :(