I tried to use an empty html.Div with a callback to dynamically populate either one of two input options into the UI at the beginning of my app (‘Online’ and ‘Offline’, in my case).
Either one of these two inputs is supposed to trigger another callback, even if they’re empty, but for some reason this second callback never triggers. Scouring the forums, I think I found a similar error, unresolved, here, and in response to it, I have tried producing my own minimal working example, with html.Div’s as print statements to check which parts of the 2nd callback run (currently they don’t).
Anyone have any advice on what error I’m making, or if this is really some bug?
###### Main imports ######
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
###### Main code ######
app = dash.Dash()
app.scripts.config.serve_locally = True
## For allowing dynamic input UI.
app.config['suppress_callback_exceptions']=True
app.layout = html.Div(children=[
html.H1(children='Basic Forecast'),
html.Div(dcc.Dropdown(id='input_dropdown', options=[{'label':'Online', 'value':'Online'},
{'label':'Offline', 'value':'Offline'}])),
html.Div(id='data_source'),
html.Div(id='output_graph')
])
@app.callback(
Output(component_id='data_source', component_property='children'),
[Input(component_id='input_dropdown', component_property='value')],
)
def dropdown_options(source):
if source == 'Online':
return dcc.Input(id='online_input', value='Search', type='text'), html.Button('Online file', id='online_clicks', n_clicks='0')
elif source == 'Offline':
return dcc.Upload(id='upload_data', children=html.Button('Offline file', id='upload_clicks', n_clicks='0'))
else:
return None
@app.callback(
Output(component_id='output_graph', component_property='children'),
[Input(component_id='online_input', component_property='value'),
Input(component_id='online_clicks', component_property='n_clicks'),
Input(component_id='upload_data', component_property='contents'),
Input(component_id='upload_clicks', component_property='n_clicks')]
)
def update_value(online_input, online_clicks, upload_data, upload_clicks):
html.Div('Testing, testing, attention please.')
if int(online_clicks) > int(upload_clicks):
return html.Div('Online input works.')
elif int(upload_clicks) > int(online_clicks):
return html.Div('Offline upload works.')
if __name__ == '__main__':
app.run_server(debug=True)