{ "metadata": { "name": "", "signature": "sha256:d75ab1c53fa3389eeac78ecf8e89beb52871950f296aad25776699b6d6125037" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Interact" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `interact` function provides a high-level interface for creating user interface controls to use in exploring code and data interactively." ] }, { "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 = '

Arguments:

\\n'\n", " for k,v in kwargs.items():\n", " s += '\\n'.format(k,v)\n", " s += '
{0}{1}
'\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": [ "

Arguments:

\n", "\n", "\n", "\n", "
a10
cTrue
bHi There
" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "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", " a=widgets.FloatSliderWidget(min=-10.0, max=10.0, step=0.1, value=5.0)\n", " )" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "

Arguments:

\n", "\n", "\n", "\n", "\n", "\n", "
Current4.99
TextType here!
zTrue
a5.0
Temp5
" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "i.widget" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "

Arguments:

\n", "\n", "\n", "\n", "\n", "\n", "
Current4.99
TextType here!
zTrue
a5.0
Temp5
" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 5 } ], "metadata": {} } ] }