{
 "metadata": {
  "name": "",
  "signature": "sha256:3f30c6e839ac39f890da34a2af6bf50bf0d99ea32f7aadc043f3e31f619e4bc9"
 },
 "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 = '<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": [
        "<IPython.core.display.HTML object>"
       ]
      }
     ],
     "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, description=\"Float (a)\")\n",
      "         )"
     ],
     "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",
        "<tr><td>Float (a)</td><td>5.0</td></tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "display_data",
       "text": [
        "<IPython.core.display.HTML object>"
       ]
      }
     ],
     "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",
        "<tr><td>Float (a)</td><td>5.0</td></tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "display_data",
       "text": [
        "<IPython.core.display.HTML object>"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}