Jupyter Interactive widgets

The notebook comes alive with the interactive widgets:

  • Part of the Jupyter project
  • BSD Licensed

Installation for the legacy notebook:

conda install -c conda-forge ipywidgets

Speeding up the bottleneck in the REPL


In [7]:
15 * 15


Out[7]:
225

In [8]:
def f(x, y):
    print(x * y)

In [9]:
from ipywidgets import *
from traitlets import dlink

In [10]:
interact(f, x=(0, 100), y=['a',  'b']);


Interactive Jupyter widgets


In [11]:
slider = FloatSlider(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Input:',
)

slider



In [12]:
slider



In [14]:
slider.value


Out[14]:
7.2

In [15]:
slider.keys


Out[15]:
['_dom_classes',
 '_model_module',
 '_model_module_version',
 '_model_name',
 '_view_count',
 '_view_module',
 '_view_module_version',
 '_view_name',
 'continuous_update',
 'description',
 'description_tooltip',
 'disabled',
 'layout',
 'max',
 'min',
 'orientation',
 'readout',
 'readout_format',
 'step',
 'style',
 'value']

In [16]:
slider.readout_format = '.4f'

In [17]:
text = FloatText(description='Value')
dlink((slider, 'value'), (text, 'value'))
text



In [18]:
slider


Widgets are represented in the back-end by a single object. Each time a widget is displayed, a new representation of that same object is created in the front-end. These representations are called views.


In [ ]:
slider

In [ ]:
ft = FloatText()

In [ ]:
def foo(change):
    ft.value = change.new

slider.observe(foo, names=['value'])

In [ ]:
ft

In [ ]:
from ipywidgets import HBox

In [ ]:
HBox([slider, slider, ft])