Separate clicks on graph updates in callbacks

Hi Folks,

I have a dash application for temperatures monitoring . I use callback functions with several entries, one of my inputs is the update option of the graph (once a day). Clicking on one of my input also executes the update that is supposed to launch once a day. How can I separate these two operations knowing that I am acting on the same output.

Thanks for your helps.

Hi, If I understand correctly what are you trying to achieve: you want to be able to refresh the chart based on all the inputs, but the data (that is loaded into hidden div stock-df_monitoring) should be refreshed only once per day.

The second interpretation is that you can change value of controls that are inputs but the the figure should be updated only based on the dataframe refresh?

Regardless of the interpretation the answer is a State component. By design every time ANY of the inputs changes, the callback if fired and collects all input and states values on firing. So if you try to update the graph only on data change, all other Inputs in your callback should be States. If you want to update on all changes to Input but not on the data change the dataframe div should be a State.

But I see here a bigger flaw - the Interval component runs only where the page is loaded in the browser. So If you want to work, you need to keep the browser window open 24h/7, and still different sessions (the same pages opened in several browsers) might fire this callback at different times.

What you really try to achieve (or what I think you want to achieve) should be done with caching. You run the callback against the database and then memoize it (good tutorial n dash docs: That way if you set cache timeout for 24 hours the next callback will hit the cache not the server.

BTW. If you really want to divide actions based on which input was fired (which from description I don’t think is the case) then the new callback_context global variable is the answer. In callback you can access app.callback_context.triggered dict to see which input fired the callback and prevent the update (raise any exception (good practice is PreventUpdate dash exception), or return no_update (also new)) or do whatever you like according to what input was fired.

1 Like