I'm trying to combine the interact function with custom Box layout.
As minimial example, let's say I put some widgets in a HBox:
xwid = FloatSlider(min=-1, max=1, description='x', continuous_update=False)
ywid = FloatSlider(min=-1, max=1, description='y', continuous_update=False)
hbox = HBox([xwid, ywid])
I can use interact:
@interact
def g(x: xwid, y: ywid):
plt.plot(x, y, 'o')
plt.xlim(-1, 1)
plt.ylim(-1, 1);
But in this way I cannot specify the HBox container. Is there a way to use interact with widgets contained in a Box?
Thanks.
I barely use interact decorator but use interactive.
widget = interactive(g)
abox = Box([widget,])
From the Using Interact.ipynb in examples:
Unlike
interact,interactivereturns aWidgetinstance rather than immediately displaying the widget.
Using HBox:
w = interactive(f, a=10, b=20)
w2 = interactive(f, a=20, b=30)
HBox([w, w2])
Please reopen if this didn't answer your question.
@hainm @gnestor, thanks, this answers my question, sorry for not following up earlier.
How about for specifying the layout WITHIN an interactive widget?
So in the example from gnestor above:
w = interactive(f, a=10, b=20)
w2 = interactive(f, a=20, b=30)
HBox([w, w2])
I'd instead like to end up with an interactive widget w, which is displayed as
HBox([a,b])
@berkerboy I think I figured it out!
you need to get the children from the widget object and then arrange them however you like.
for example, if I want widgets a and b laid out horizontal, I could do
w = interactive(f, a=10, b=20)
HBox(w.children)
Related #1731
Most helpful comment
How about for specifying the layout WITHIN an interactive widget?
So in the example from gnestor above:
I'd instead like to end up with an interactive widget
w, which is displayed asHBox([a,b])