Search code examples
ipywidgets

How to use interactive with a Box containing widgets?


Using interactive is fairly simple with multiple widgets, for example:

interactive(foo, w1=widget1, w2=widget2, ...)

However I would like to layout these widgets in a specific manner, using combinations of VBox and HBox. Question is, how can I use interative with a box?

I have tried a couple of ways such as calling interactive with the widgets of the Box then displaying the box itself but that does not seem to work.


Solution

  • It is in the widgets documentation:

    In addition to interact, IPython provides another function, interactive, that is useful when you want to reuse the widgets that are produced or access the data that is bound to the UI controls. [...] Unlike interact, interactive returns a Widget instance rather than immediately displaying the widget. The widget is a Box, which is a container for other widgets.

    So here you already have w as a Box container for which you can change the layout properties.

    w = interactive(foo, w1=widget1, w2=widget2)