I am trying to assign interactive widgets box output to dataframe (in the code it is df2). I would like to have dataframe (df2) values change anytime inputs are changed in the box. Could you please advise how code should be modified?
Please note that code is detailed, because I would like that once user change one value in the box others would not change and thus user would have flexibility. If there is more succinct way then I would highly appreciate if you could advise it. Thank you in advance.
table_style = {'description_width': 'initial'}
table_layout = {'width':'150px', 'min_width':'150px', 'height':'28px',
'min_height':'28px'}
row_layout = {'width':'200px', 'min_width':'200px'}
style_label = {'description_width': '150px'}
scenarios = ['Worst', 'Base', 'Best']
floatinput1 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='Worst',disabled=False, layout=table_layout,
style=table_style)
floatinput2 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput3 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput4 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput5 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput6 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='Base',disabled=False, layout=table_layout, style=table_style)
floatinput7 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput8 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput9 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput10 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput11 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='Best',disabled=False, layout=table_layout, style=table_style)
floatinput12 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput13 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput14 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
floatinput15 = BoundedFloatText(value=0, min = 0, max = 1, step = 0.001,
description='',disabled=False, layout=table_layout, style=table_style)
hbox1 = HBox(( floatinput1, floatinput2, floatinput3, floatinput4,
floatinput5))
hbox2 = HBox(( floatinput6, floatinput7, floatinput8, floatinput9,
floatinput10))
hbox3 = HBox(( floatinput11, floatinput12, floatinput13, floatinput14,
floatinput15))
input_table = VBox((hbox1, hbox2, hbox3))
input_table
df2 = pd.DataFrame(np.reshape([0]*15, (3,5)))
def process_table(fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8, fn9, fn10, fn11,
fn12, fn13, fn14, fn15 ):
table_list = [fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8, fn9, fn10, fn11,
fn12, fn13, fn14, fn15]
df = pd.DataFrame(np.reshape(table_list, (3,5)))
df.index = scenarios
df2 = df
print(df)
mapping =
{'fn1':floatinput1,'fn2':floatinput2,'fn3':floatinput3,'fn4':floatinput4,'fn5':floatinput5,'fn6':floatinput6,'fn7':floatinput7,'fn8':floatinput8, 'fn9':floatinput9, 'fn9':floatinput9, 'fn10':floatinput10, 'fn11':floatinput11, 'fn12':floatinput12,'fn13':floatinput13, 'fn14':floatinput14, 'fn15':floatinput15}
interactive_bind = interactive_output(process_table, mapping )
display(input_table, interactive_bind )
df2