mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
4.1 KiB
4.1 KiB
Interact¶
The interact
function provides a high-level interface for creating user interface controls to use in exploring code and data interactively.
In [1]:
from IPython.html.widgets import interact, interactive, fixed from IPython.html import widgets from IPython.display import clear_output, display, HTML
Basic interact¶
Here is a simple function that displays its arguments as an HTML table:
In [2]:
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))
In [3]:
show_args(a=10, b='Hi There', c=True)
Arguments:
a | 10 |
c | True |
b | Hi There |
Let's use this function to explore how interact
works.
In [4]:
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, description="Float (a)") )
Arguments:
Current | 4.99 |
Text | Type here! |
z | True |
Temp | 5 |
Float (a) | 5.0 |
In [5]:
i.widget
Arguments:
Current | 4.99 |
Text | Type here! |
z | True |
Temp | 5 |
Float (a) | 5.0 |