The interact
function provides a high-level interface for creating user interface controls to use in exploring code and data interactively.
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
from IPython.display import clear_output, display, HTML
Here is a simple function that displays its arguments as an HTML table:
def show_args(**kwargs):
s = '<h3>Arguments:</h3><table>\n'
for k,v in kwargs.items():
s += '<tr><td>{0}</td><td>{1}</td></tr>\n'.format(k,v)
s += '</table>'
display(HTML(s))
show_args(a=10, b='Hi There', c=True)
a | 10 |
c | True |
b | Hi There |
Let's use this function to explore how interact
works.
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)
)
Current | 4.99 |
Text | Type here! |
z | True |
a | 5.0 |
Temp | 5 |
i.widget
Current | 4.99 |
Text | Type here! |
z | True |
a | 5.0 |
Temp | 5 |