Reputation: 5565
I have a blackbox function which accepts ~10 integer inputs. The function returns a pandas dataframe, and I would like to capture the output window (by using bbwidget.children) and display elsewhere in a Layout. So far interact/interactive seems the bet for this.
I have defined a list of widgets to use as inputs to the function; can I pass this list to interact/interactive? From my attempts so far, I need to specify ALL of the input widgets beforehand, and pass them all individually in a call to interactive.
Here's conceptually what I would like to do (just using the dictcomp in the function call to illustrate that each widget maps to a certain input):
widgetlist = [list of int input widgets]
inputlist = [list of function inputs]
def bbfunc(inputlist):
return df
bbwidget = ipyw.interactive(bbfunc, {k:v for k,v in zip(widgetlist,inputlist)})
Is there some special syntax or option for a call to interact/interactive that could allow for this?
Upvotes: 2
Views: 156
Reputation: 5565
I think I found my own answer:
import ipywidgets as ipyw
from IPython.display import display
def f(x,y):
return x + y
x,y = 0,0
xwidget = ipyw.IntSlider(min=-10,max=30,step=1,value=10)
ywidget = ipyw.IntSlider(min=-10,max=30,step=1,value=10)
widgetdict = {k:v for k,v in zip(('x','y'),(xwidget,ywidget))}
testwidg = ipyw.interact(f, **widgetdict)
Upvotes: 1