Hello,
After a non trivial amount of troubleshooting I came to realize that a call back to populate options which, on first render, either does not execute a return statement (because the return is in an if statement that doesn’t fire initially) or returns None will disable the abilty for that callback to populate options in subsequent call backs.
An example:
this will never populate options
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(id='my-id', placeholder='enter text sperated by comma', type='text'),
dbc.Button('show charts',id='button',color='primary', disabled=False),
dcc.Dropdown(id='dd')
])
@app.callback(Output('dd','options'),
[Input('button', 'n_clicks')],
[State('my-id', 'value')])
def update_selectStep_list(clicks,prodSteps):
if prodSteps is not None:
vals=[i.strip() for i in prodSteps.upper().split(',')]
return [{'label': i, 'value': i} for i in vals]
else:
return None
if __name__ == "__main__":
app.run_server(debug=False)
Nor will this
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(id='my-id', placeholder='enter text sperated by comma', type='text'),
dbc.Button('show charts',id='button',color='primary', disabled=False),
dcc.Dropdown(id='dd')
])
@app.callback(Output('dd','options'),
[Input('button', 'n_clicks')],
[State('my-id', 'value')])
def update_selectStep_list(clicks,prodSteps):
if prodSteps is not None:
vals=[i.strip() for i in prodSteps.upper().split(',')]
return [{'label': i, 'value': i} for i in vals]
if __name__ == "__main__":
app.run_server(debug=False)
but this WILL
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(id='my-id', placeholder='enter text sperated by comma', type='text'),
dbc.Button('show charts',id='button',color='primary', disabled=False),
dcc.Dropdown(id='dd')
])
@app.callback(Output('dd','options'),
[Input('button', 'n_clicks')],
[State('my-id', 'value')])
def update_selectStep_list(clicks,prodSteps):
if prodSteps is not None:
vals=[i.strip() for i in prodSteps.upper().split(',')]
return [{'label': i, 'value': i} for i in vals]
else:
return {}
if __name__ == "__main__":
app.run_server(debug=False)
This seems like odd behavior since in the 2nd example the return statement is not being fired at all.
Thanks for the insight.