I am trying to create a dynamic controls based on users inputs. I am trying to mimic one of example in forum (I cant find it now…). I don’t understand why the last callback function is not working…
Here is the simplified code:
dy_ctrls = {}
test_ids = ['option2_ALL-esc', 'option2_ALL-esc-b', 'option2_ALL-sz', 'option1_ALL-b',
'option1_ALL-b-csc', 'option1_ALL-a-esc', 'option2_ALL-esc-a', 'option1_ALL-b-sz',
'option2_ALL-csc-b', 'option2_ALL-csc-a', 'option2_ALL-sz-b', 'option1_ALL-a',
'option2_ALL-csc', 'option1_ALL-b-esc', 'option1_ALL-a-csc']
for i in test_ids:
dy_ctrls[i] = dcc.Input(placeholder='Enter a value...', type='number', value= 0, id = i)
app = dash.Dash()
app.config['suppress_callback_exceptions'] = True
app.layout = html.Div([
dcc.RadioItems(
options=[
{'label': 'option1', 'value': 'option1'},
{'label': 'option2', 'value': 'option2'}
],
value='option1',
id = 'selection'
),
html.Button(id='submit', type='click', children='OK', n_clicks =0),
html.Div(id = 'input4users'),
html.Div(id = 'test'),
html.P('something')
])
@app.callback(Output('input4users', 'children'),
[],
[State('selection', 'value')],
[Event('submit', 'click')])
def update_table(i):
output_list = []
print('check pts-1, i=', i)
for j in dy_ctrls.keys():
if j.split('_')[0] == i:
print(dy_ctrls[j])
output_list.append(dy_ctrls[j])
return html.Div(output_list)
@app.callback(Output('test', 'children'),
[Input(i, 'value') for i in test_ids])
def update_value(*arg):
print('check pts 2')
lb_value = 0
for i in arg:
print(i)
lb_value = lb_value + i
return "Input value = {}".format(lb_value)
if __name__ == '__main__':
app.run_server(debug=True)