Hi,
I have a small demo app below, which includes a fast callback, a slow callback, and a sum field. The callback for the sum field has both the slow and the fast callback as input.
Because of the multiple inputs the sum callback will wait for the slow callback to finish before it triggers. To improve performance, I’d like the sum callback to be triggered any time there is a change in any of the input fields, even when the slow callback is processing. Is this possible? Any known work arounds?
Thanks =)
import dash, time
import dash_html_components as html
from dash.dependencies import Input, Output, State
app = dash.Dash()
server = app.server
app.layout = html.Div([
html.Button('Slow', id='slow_button'),
html.Button('Fast', id='fast_button'),
html.Div([
"Slow:",
html.Div(id='slow_out'),
"Fast:",
html.Div(id='fast_out'),
"Sum:",
html.Div(id='sum_out'),
])
])
@app.callback(
Output('slow_out', 'children'),
Input('slow_button', 'n_clicks')
)
def slow(slow_clicks):
time.sleep(5)
return slow_clicks
app.clientside_callback(
"""
function(fast_clicks){
return fast_clicks
}
""",
Output('fast_out', 'children'),
Input('fast_button', 'n_clicks')
)
app.clientside_callback(
"""
function(fast_number, slow_number){
return fast_number + slow_number
}
""",
Output('sum_out', 'children'),
[Input('fast_out', 'children'), Input('slow_out', 'children')]
)
if __name__ == '__main__':
app.run_server()