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 [1]:
12 * 12


Out[1]:
144

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

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

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


Interactive Jupyter widgets


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

slider



In [20]:
slider



In [21]:
slider.value = 8

In [22]:
slider.keys


Out[22]:
['_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 [23]:
slider.readout_format = '.4f'

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



In [25]:
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 [26]:
slider



In [27]:
ft = FloatText()

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

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

In [29]:
ft



In [30]:
from ipywidgets import HBox

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



In [ ]: