I have made an app using Dash which allows users to drop an excel-file, perform some calculations using the data within this file and at the end make a nice plot. However, the data needs to meet certain criteria otherwise the programm will not be able to perform the calculations (correctly). In my own offline script I have several if statements with some prints that show me what could be a cause for possible problems, but I also want to show some of these warnings to users to help them in correcting data and parameter settings so the calculations will run correctly.
My idea was to show these warnings using Alerts, however, I can’t find how to do this as the calculation is performed in a single function and contains a loop over the data. Ideally I would end up with something like this:
if variable > 10:
Call Alert and display it
The reason why I haven’t succeeded yet is because I’m a bit confused about the callback. To display the alert I call another (standard) function which sets the specific alert open → True, so it gets displayed. However, this function requires an input, but as I calculate this variable within another calculation I can’t store it and turn it into an input. Currently I’m using this to open the alarm as soon as a file is being uploaded, but I want to only open the Alert if I state it in an if statement within the calculation:
def toggle_alert(filename, is_open):
return not is_open
Any ideas on how I can solve this problem with callbacks, without me having to completly rewrite the script and split the main function?