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.
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.
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. [...] Unlikeinteract
,interactive
returns aWidget
instance rather than immediately displaying the widget. The widget is aBox
, 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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With