I'm trying to run a Python script in a Dash callback function but my current code is not doing it as I intended. For example, there's a button called "Open" and once a user click on it, it will open a modal and run the python script. On the modal page, there's another button called "Close" and if the user click on the close button, it will simply close the modal page but not run the python script.
This is the current callback function I have but the problem is that it runs the python script when I hit the "Close" button as well. Which part should I change to make the python script run only when a user click on the "Open" button but not the "Close" button?
@app.callback(
Output("modal", "is_open"),
[Input("open-button", "n_clicks"), Input("close-button", "n_clicks")],
[State("modal", "is_open")],
)
def activate_modal(n1, n2, is_open):
if n1 or n2:
script_fn = my_script.py"
exec(open(script_fn).read())
return not is_open
return is_open