@dash_user_583280747 wrote:
Hello,
I have an app that takes inputs and runs a long computation (> 10 minutes). The output of this computation is used to populate part of the app.layout. When I run the computation, the app gives me a callback error updating children.
I have tried the techniques for Sharing State Between Callbacks (Link), but they also fail.
Is there a way to get the app to wait for the output before throwing this error?
Here is a small reproducible sample:
import dash import dash_core_components as dcc import dash_html_components as html from dash.dependencies import State, Input, Output from dash.exceptions import PreventUpdate import time app = dash.Dash( __name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}] ) app.layout = html.Div([ html.Button( "Run", id="button1", ), dcc.Slider( id="slider1", min=0, max=10, step=1, value=0, ), dcc.Loading( id="Loading1", children=[ html.Div(id="out1", children=[html.P("Nothing yet")]), ], type="default" ) ]) @app.callback(Output('out1', 'children'), [Input('button1', 'n_clicks')], [State('slider1', 'value')]) def update_page(n_clicks, value): if n_clicks is None: raise PreventUpdate else: time.sleep(100) out_string = "The output is " + str(value) return html.P(out_string) if __name__ == '__main__': app.run_server(debug=True)
Alternatively, do you think it would be better to have a callback with no output just to trigger the calculation?
Thanks,
Anthony
Posts: 1
Participants: 1