My issue though stems from not needing the n_clicks values, but simply the acknowledgement that a button was pressed. I’m trying to create a button that resets all dropdowns to their default values when clicked. Not sure how this can be done with n_clicks though. Any suggestions?
That wont work for my case: I have an output that can be changed based off inputs, but if the button is pressed, the output should be reset the default component.
The idea here is that I’m creating dependant drop downs that change based on the other dropdown choices. Now since I can’t have more than one callback on a single output component, then I would have to do some type of logic statement that produces a different return value. Here is something I thought of, but not sure how to implement. Let me know what your thoughts are.
Right now you it’s not possible to tell which component has changed, you can only get the current state of all of the components that the callbacks depend on.
That is a good suggestion, but my issue is that dropdown b is also dependent on other dropdown inputs, I couldn’t just add the button as the only input.
Those are the dropdown-b options though right? Is the value really dependent on other dropdown inputs as well? (if so, should it really even be a dropdown?)
Each dropdown corresponds to a column in the table and is used to filter that dataframe. Take the example below. If Americas is chosen in dropdown A, than dropdown b should only show USA, Canada as options and only Switzerland and Germany for dropdown c.
Or another example: if Germany is chosen from dropdown b, than dropdown a’s options should only be EMEA and dropdown c’s options should only show USA and Japan.
The purpose of this is to improve UI by removing options from the dropdowns that will not have any data based on the filter created.
It seems to me that the example I posted a little ways up should work fine for this example (except I confused what was A, B, and C). So something like this:
There isn’t anyway to get around this right now besides writing this Dash feature into dash’s backend and front-end (or contracting Plotly to build this feature out)
@rkahhale I actually ended up writing this app in vanilla javascript. While dash is an amazing library for building visualizations, it ended up not being the simplest solution for this particular project.
That said, I’d still be happy to help you with your issue. Do you mind opening a new thread though? Tag me in it.
I faced the same issue and the solution that I found out is to set the button as ‘Input’ and the other inputs as ‘State’. Then the callback will only be launched when the button is clicked and not when the other inputs are changed.
I had a similar problem. I have several html and dcc components which are all used to update one graph. I wanted to use a button for exporting the graph using plotly.offline. The solution I found for determining whether or not the button is the last activated component, is comparing the n_click_timestamp to the current timestamp, i.e.: (pseudo-code)
if n_clicks_timestamp > (datetime.datetime.now().timestamp.()-1 second):
Export graph
I hope this helps
Its an effective way to figure out what button or any other component has changed, and update another component based on which one was triggered. It uses hidden divs to store the timestamps of when each component was called, and compares to the current time to figure out which one was called last - similar to nahal626 and Harold’s suggestions. This referenced link may be useful since its all written out.