Dash DCC button doesn't run Python script on live deployement

For automated testing purposes I have created a framework for deploying tests automatically. This is integrated on a seperate server using the task scheduler. This works fine. However, I want to give people the opportunity to deploy a test mannualy, by using a Dash dashboard with buttons for deploying the tests.

The problem I encounter is that when I deploy the dabo locally via Jupyter, the scripts behind the buttons are deployed nicely, by using this code…:

def deploy_test_scl(n_clicks):
    # Don't run unless the button has been pressed...
    if n_clicks is None:

        raise PreventUpdate
    else:
        os.chdir('<path_to_file>')
        call(["python", "main.py"])
        return  "tests are finished, see Power BI for the results"

…resulting in a visible loading element which stops when the tests are fully run, returning the message.

However, when I apply this code in the app.py file and the dabo is deployed via IIS manager, the code won’t run and the script is not called. Even when I comment the call function and set only the return function, nothing will appear.

I have also tried the python ‘subprocess’ package, which doesn’t work either.

Other neccessary information(?):

  • The deployement of the website (app.py), is a the inetpub/wwwroot directory.
  • the website is deployed via the IIS manager by using the FASTCGI module.
  • the fastcgi.py file is created within a virtual environment and placed in the wwwroot directory.

The only issue I can think of is to elevate the privileges to admin, but I am not sure. Furthermore, I have no other ideas which could cause the problem of not running the main.py script for deploying the tests, or even returning the text. It even seems the button is not able to change the directory…

Can someone point me in the right direction why the python script is not called and thereby run?

I’m afraid I can only ask standard questions:

  • do any errors appear in the browser tools console or network tabs when the button is pushed?
  • in the deployed version, do the callback Input/Output/State element IDs exist in the layout, and are the usual Dash rules satisfied (no circular dependencies, ‘allow_duplicates=True’ whenever needed)?

@Hilbert What if instead of doing call(["python", "main.py"]) you create a function in main.py, import it and then call the function? Also, n_clicks is a number with a default value of 0 so if n_clicks is None: will never be true.

from main import create_test  # where create_test is your function


def deploy_test_scl(n_clicks):
    # Don't run unless the button has been pressed...
    if n_clicks == 0:
        raise PreventUpdate
    else:
        create_test()
        return  "tests are finished, see Power BI for the results"

@PyGuy thanks for the feedback. I have tried to change te code to the following (without importing from a separate file):


def deploy_test_scl(n_clicks):
    if n_clicks == 0:
        raise PreventUpdate
    else:
        os.chdir("<path to featurefiles>'")
        from behave.__main__ import main as behave_main
        behave_main(r'<path to featurefiles>')

The from behave.main import main as behave_main is mentioned in the main.py file.
Locally, in Jupyter it works flawlessly, but when I deploy it via the IIS manager, nothing happend. I am out of ideas and do not get any errors returned.

I don’t have any ambigous callbacks in my script, so that should not be an error.

Hello @Hilbert,

Have you tried manually running the script on the IIS server?

The IIS server doesnt sound like it is a venv, you should more than likely spin up a venv and pass the path in the code for triggering the script.

I am not sure how I run a script manually on the IIS server. It’s not my code as it runs fine on localhost and it is able to run the script on multiple ways (subprocess call, from behave.main, os.startfile(“run.bat”). It’s just as the IIS server is not able to invoke the script.

I also read that the IIS server is more or less an end of life product, which almost let me make the decision to use an other web server (nginx or apache). Or even an Python based on like gunicorn or waitress. I am a bit frustrated that the IIS manager does not invoke the script and I am not able to find where this is going wrong. I even tried to make new folders (without virtual env) to try if the script would be invoked. Just nothing happens with or without… I even copied al my tests to the wwwroot folder to see if they would be invoked, as I also had some trouble to change the directory outside the wwwroot folder. Which implies the wwwroot folder is also a venv. But also this step doesn’t work.

It seems the live deployement is not able to invoke the script in any way.

Are there other suggestion I could try (without IIS?)

IIS is just a routing mechanism that goes to an app, it’s your app service that is responsible for running the script.

If you can’t control the device other than dropping your files to a location, then it is probably blocking the call. Or you don’t have the required libraries your script needs to run in your requirements.txt file.

What you can do is create a venv and make sure that you can run your script file from just the libraries in the requirements.txt. If you can’t run it, import the missing libraries and make sure to add them to your requirements file.

Once you do that, you can try running it again on the other server.

Also, dash will crash in production if you run into import errors and thus you don’t get any response because the server is essentially rebooting.

I have a way that you can wrap callbacks to have it send you an error or a fallback message, you could give that a shot and see if it helps you get to the bottom of the issue.

Alright, I finally got it to work. There are two main faults on my side. I checked every package installment and the most where there, but some apparrently importent packages where missing. These where installed. Lastly, I put everything in the wwwroot folder, not knowing this is a special kind of folder too (some kind of venv?). This means my project structure need some tweaks. I have tried to establish a symlink to the projectfolder, but I did not manage to get this work.

For now, the result is that the tests will be deployed manually by pressing the button, causing the server to crash due too low memory and exceedingly high CPU usage.

Thanks for all the kind help! I learned a lot from this experience!

Regards, Hilbert