Disable button after click and then reactivate button after job finished

Hi there,
I have a submit button which I expect the following behavior:

  1. click submit button
  2. deactivate button and run some time consuming jobs
  3. Once the jobs are done, enable the submit button

What I need to help is, is it possible to return ‘disabled’ state at first (because jobs are executing) and then return an ‘active’ state once jobs are done. Generally speaking, is it possible to deactivate a button for some time spans?

I’ve search posts in the community but did’t find an answer which really solves my problem.
Thank you for your help!

Here are my codes:
id = ‘btn’,
disabled = False

Output(“btn”, “disabled”),
Input(“btn”, “n_clicks”),
State(“btn”, “disabled”),
def deactivate_btn_while_running(n1, disabled):
print(n1, disabled)
# execute some computing jobs
# if not done return disabled (need help)
# else return not disabled (need)

Hello @KCL0827,

This is available from using background callbacks. :slight_smile:

Please check out the below:


Dear @jinnyzor, thank you for your answer and this it what I’m searching for. However, when I execute the code from the example 2, I’ve got the following error. Is this due to my python package?

Thank you for your answer and help. :wink:


This is due to an issue with background caching, windows and pages. More specifically the dill package, which is out of dash’s control.

Bring your callback into your app.py and see if it will work from there.

1 Like

Hi @jinnyzor, you are right! Thanks. But is there a workaround for using background app in multi page? Thanks again.

That is the workaround. :stuck_out_tongue_winking_eye:

Until the dill package is fixed, there is an issue with pages on windows.

However, if you are going to host the server on a different os, you should be able to do some without issue.

You mean I can ignore the error message as long as the function works? :laughing:

You’re still getting the abc error?

Or is it a different error? You brought your callback into your app.py and removed it from the other?

Check out this thread:

I mean background callback works correctly under one single app.py. However, my app is using multiple page and therefore I still get error due to dill.

The pages can be split up into their different files, the callbacks needed to be all in the single app.py.

At least, back when I was testing this, and I had no error with abc.

1 Like

I’ll try to move the app needing background call back to app.py. The rest page files I’ll keep them separate. Thanks!

1 Like

To clarify, “app” in that sense meant just the callback. You can’t mix page_folder locations.

Yes, the app are the functions need backgroud_callback instead of app.py file. :grinning:

1 Like

I ran into the same issue (cannot pickle '_abc._abc_data') using dill 0.3.6. This issue is fixed in dill 0.3.7. However, another issue came up, which for me was related to ContextVar not being pickle-able.

I found out that the root cause was related to using @app.callback to define callbacks rather than using from dash import callback in combination with @callback.

1 Like