Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use interactive with a Box containing widgets?

Tags:

ipywidgets

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.

like image 713
Eric Thibodeau Laufer Avatar asked Sep 08 '16 18:09

Eric Thibodeau Laufer


People also ask

What is Python Ipywidgets?

IPyWidgets is a Python library of HTML interactive widgets for Jupyter notebook. Each UI element in the library can respond to events and invokes specified event handler functions. They enhance the interactive feature of Jupyter notebook application.


2 Answers

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)
like image 87
Ely Avatar answered Oct 13 '22 11:10

Ely


I have encountered same issue, and figured out that we need to use interactive_output.

out = interactive_output(foo, {"w1":w1, "w2":w2, "w3":w3, "w4":w4})
vbox1 = VBox([w1, w2])
vbox2 = VBoX([w3, w4])
ui = HBox([vbox1, vbox2])

accordian = Accordian(children=[ui])
accordian.set_title(0, 'Title')

display(accordian, out)
like image 36
Seal Avatar answered Oct 13 '22 09:10

Seal