IPython Notebook two functions that depend on value widget
Question: I have an IPython noteboook with **two widets** (`carW` and `speedW`) and
**two functions** (`print_car` and `print_car_and_speed`) that depend on the
values of the widget. What I'm trying to achieve is that the output of
`print_car` changes when the value of `carW` changes and that the output of
`print_car_and_speed` changes whenever either the value of `carW` or `speedW`
change.

Here is the code that I'm using:

    
    
    from IPython.html import widgets
    from IPython.display import display
    
    def print_car(car):
        print "Selected car: {}".format(car)
    
    def print_car_and_speed(car, speed):
        print "Driving {} with speed: {}".format(car, speed)
    
    carW = widgets.Dropdown(options=['Prius', 'Porsche'])
    carW.value = 'Prius'
    
    i = widgets.interactive(print_car, car=carW)
    display(i)
    
    speedW = widgets.FloatSlider()
    
    j = widgets.interactive(print_car_and_speed, car=carW, speed=speedW)
    display(j)
    

The problem with this code is that the **output of** `print_car` **is not
displayed** for me. If I comment the last two lines however, the output of
`print_car` is displayed as I would expect it to be.

Ideally I would like the output to follow the following format:

  * `carW` widget
  * output of `print_car`
  * `speedW` widget (don't repeat `carW` widget)
  * output of `print_car_and_speed`

Would be great if you could give me pointers how I can achieve this. Thank
you!


Answer: I figured out how to display the output of two functions that depend on the
value of one widget so that they don't get in each other's way via an
intermediate handler that broadcasts the value of the widget to two output
functions:

    
    
    from IPython.html import widgets
    from IPython.display import display
    
    def handler_car(car):
        print_car(car)
        print_car_and_speed(car, speedW.value)
    
    def handler_speed(speed):
        print_car(carW.value)
        print_car_and_speed(carW.value, speed)
    
    def print_car(car):
        print "Selected car: {}".format(car)
    
    def print_car_and_speed(car, speed):
        print "Driving {} with speed: {}".format(car, speed)
    
    carW = widgets.Dropdown(options=['Prius', 'Porsche'])
    carW.value = 'Prius'
    
    speedW = widgets.FloatSlider()
    
    i = widgets.interactive(handler_car, car=carW)
    display(i)
    
    j = widgets.interactive(handler_speed, speed=speedW)
    display(j)
    

The only bit that's missing for me now is to arrange this in the right order:

  * `carW` widget
  * output of `print_car`
  * `speedW` widget (don't repeat `carW` widget)
  * output of `print_car_and_speed`

