Using Interact.ipynb
169 lines
| 4.1 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r16057 | { | |
"metadata": { | |||
"name": "", | |||
Jessica B. Hamrick
|
r16657 | "signature": "sha256:3f30c6e839ac39f890da34a2af6bf50bf0d99ea32f7aadc043f3e31f619e4bc9" | |
Brian E. Granger
|
r16057 | }, | |
"nbformat": 3, | |||
"nbformat_minor": 0, | |||
"worksheets": [ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "heading", | |||
"level": 1, | |||
"metadata": {}, | |||
"source": [ | |||
Brian E. Granger
|
r16092 | "Interact" | |
Brian E. Granger
|
r16057 | ] | |
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Brian E. Granger
|
r16092 | "The `interact` function provides a high-level interface for creating user interface controls to use in exploring code and data interactively." | |
Brian E. Granger
|
r16057 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"from IPython.html.widgets import interact, interactive, fixed\n", | |||
"from IPython.html import widgets\n", | |||
"from IPython.display import clear_output, display, HTML" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 1 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"source": [ | |||
"Basic interact" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"Here is a simple function that displays its arguments as an HTML table:" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"def show_args(**kwargs):\n", | |||
" s = '<h3>Arguments:</h3><table>\\n'\n", | |||
" for k,v in kwargs.items():\n", | |||
" s += '<tr><td>{0}</td><td>{1}</td></tr>\\n'.format(k,v)\n", | |||
" s += '</table>'\n", | |||
" display(HTML(s))" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 2 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"show_args(a=10, b='Hi There', c=True)" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"html": [ | |||
"<h3>Arguments:</h3><table>\n", | |||
"<tr><td>a</td><td>10</td></tr>\n", | |||
"<tr><td>c</td><td>True</td></tr>\n", | |||
"<tr><td>b</td><td>Hi There</td></tr>\n", | |||
"</table>" | |||
], | |||
"metadata": {}, | |||
"output_type": "display_data", | |||
"text": [ | |||
Jessica B. Hamrick
|
r16657 | "<IPython.core.display.HTML object>" | |
Brian E. Granger
|
r16057 | ] | |
} | |||
], | |||
"prompt_number": 3 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"Let's use this function to explore how `interact` works." | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"i = interact(show_args,\n", | |||
" Temp=(0,10),\n", | |||
" Current=(0.,10.,0.01),\n", | |||
" z=True,\n", | |||
" Text=u'Type here!',\n", | |||
" #Algorithm=['This','That','Other'],\n", | |||
Jessica B. Hamrick
|
r16657 | " a=widgets.FloatSliderWidget(min=-10.0, max=10.0, step=0.1, value=5.0, description=\"Float (a)\")\n", | |
Brian E. Granger
|
r16057 | " )" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"html": [ | |||
"<h3>Arguments:</h3><table>\n", | |||
"<tr><td>Current</td><td>4.99</td></tr>\n", | |||
"<tr><td>Text</td><td>Type here!</td></tr>\n", | |||
"<tr><td>z</td><td>True</td></tr>\n", | |||
"<tr><td>Temp</td><td>5</td></tr>\n", | |||
Jessica B. Hamrick
|
r16657 | "<tr><td>Float (a)</td><td>5.0</td></tr>\n", | |
Brian E. Granger
|
r16057 | "</table>" | |
], | |||
"metadata": {}, | |||
"output_type": "display_data", | |||
"text": [ | |||
Jessica B. Hamrick
|
r16657 | "<IPython.core.display.HTML object>" | |
Brian E. Granger
|
r16057 | ] | |
} | |||
], | |||
"prompt_number": 4 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"i.widget" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"html": [ | |||
"<h3>Arguments:</h3><table>\n", | |||
"<tr><td>Current</td><td>4.99</td></tr>\n", | |||
"<tr><td>Text</td><td>Type here!</td></tr>\n", | |||
"<tr><td>z</td><td>True</td></tr>\n", | |||
"<tr><td>Temp</td><td>5</td></tr>\n", | |||
Jessica B. Hamrick
|
r16657 | "<tr><td>Float (a)</td><td>5.0</td></tr>\n", | |
Brian E. Granger
|
r16057 | "</table>" | |
], | |||
"metadata": {}, | |||
"output_type": "display_data", | |||
"text": [ | |||
Jessica B. Hamrick
|
r16657 | "<IPython.core.display.HTML object>" | |
Brian E. Granger
|
r16057 | ] | |
} | |||
], | |||
"prompt_number": 5 | |||
} | |||
], | |||
"metadata": {} | |||
} | |||
] | |||
} |