-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
So, it is really hard for me to adequately describe this bug in the first place, since the presence of a seemingly unrelated additional Output in the same callback is what determines if it is triggered.
I was writing a simple demo app that features a line-graph being updated by a dcc.Interval object.
- I press a button,
- graph is populated with a nice line,
- this turns on the
dcc.Interval(by settingmax_intervalsto-1), dcc.Intervalthen further continues updating the graph. Afterwards, the higher then_intervals, the higher the line plotted by the correspondingdcc.Graphobject.
After some tinkering, I uncovered this bug. My MWE below displays the bug. To see the normal behavior of the code, simply delete the 4 #'s in the bottom callback.
Is this a bug, or something strange I am missing?
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from dash.dependencies import Input, Output, State
###### Setup ######
app = dash.Dash(dev_tools_hot_reload=True)
app.scripts.config.serve_locally = True
app.config['suppress_callback_exceptions'] = True
###### Main code ######
app.layout = html.Div(children=[
dcc.Interval(id='update', interval=1*1000, n_intervals=0,
max_intervals=0), ## Interval component is disabled as default through max_intervas
html.Div(children=[html.Label(id='Label', children='Just a Label.')]),
## Button triggering graph to populate with random data.
html.Div(children=[html.Button(id='button', children='Populate graph.')]),
dcc.Graph(id='Graph_triggered_by_Interval')
]
)
@app.callback(
Output(component_id='Label', component_property='children'),
[Input(component_id='update', component_property='n_intervals'),
Input(component_id='update', component_property='max_intervals'),
Input(component_id='update', component_property='disabled')]
)
def check_interval_update(n_intervals, max_intervals, disabled):
return 'n_intervals: {}, max_intervals: {}, disabled: {}'.format(n_intervals, max_intervals, disabled)
## Callback with error.
@app.callback(
# [
Output(component_id='Graph_triggered_by_Interval', component_property='figure'),
# Output(component_id='update', component_property='max_intervals')],
[Input(component_id='update', component_property='n_intervals'),
Input(component_id='button', component_property='n_clicks_timestamp')]
)
def update_graph(update, button):
if not update:
update = 1
print('\nInterval counter: {}\n'.format(update))
if button:
if update == 1:
print('\nThis is what should be printed each time after un-disabling interval (letting it go again).\n')
return {'data': [{'y': [i**2 for i in range(100)]}]}#, -1
elif update > 1:
return {'data': [{'y': [i**2 for i in range(update)]}]}#, -1
if __name__ == '__main__':
app.run_server(debug=True)
Metadata
Metadata
Assignees
Labels
No labels