dbc.Button (button from dash_bootstrap_components)

I want to disable the dbc.Button for the time when calculations are running, how Can I achieve this,
Thank you

hi @SaadKhan
I think the background_callback would be a good option here. Feel free to read the intro post to the background callback. Toward the end of that section, you’ll see a gif of a button deactivating while calculations are running.
You can also find a working example code in our docs.

hi, @adamschroeder Thank you for such a detailed article,
It is working but the delay is too much even if I remove the time.sleep(2.0), it is still taking a little long to restore the button. Is there anything for this?
Thank you once again

the delay is too long? How long does your calculation take?

The simplest calculations of Moving Average take approximately 2 3 seconds, but the button is disabled for 6 to 7 seconds,

the same problem in another way: with SARIMAX, the calculations are running for 20 25 seconds but the button appears before the end of the calculations.

This means they are not synchronized

That shouldn’t happen. Can you share the code and sample data with us?

its almost 500 lines, can i post github link here please?

1 Like
        html.Div([html.P(id='run-calc', children=['Calculations are not yet Started'])]),
        html.Button(id='run-pred', n_clicks=0, children='Run Forecast', style={'weight': 'bold'}),
        html.Button(id='stop-pred', n_clicks=0, children='Stop Forecast', style={'weight': 'bold'}),


output=Output(‘run-calc’, ‘children’),
inputs=Input(‘run-pred’, ‘n_clicks’),
(Output(‘run-pred’, ‘disabled’), True, False),
(Output(‘stop-pred’, ‘disabled’), True, False),
cancel=[Input(‘stop-pred’, ‘n_clicks’)],
def run_calculations(n_clicks):
return [f"Click on Run to Start Calculations or Stop to Cancel the Calculations"]

I am working on live data from yahoo finance, for live forecasting and making my whole web app through the dash

500 lines is very long. It doesn’t have to be your code and your data. Instead, can you create a similar sample app, that is taking sample data and replicate this error (a 2-3 second calculation, but the button is disabled of 6-7 seconds)?