Ive tried several times (on mac), but I still end up with the same scenario. The components have the property n_clicks_previous but the value isn’t updated on click it is always None (even though the default is set to 0, n_clicks also starts as None). I tested it using the following:
Will you be making a pull request to get this merged into master? If you do I can use the official build. I would like to know why I can’t get it working though!
one thing that I forgot to mention in my instruction (which is critical to build and install python egg file locally) (and having forgotten i spent last hour trying to recover that knowledge!) is that you need to run in the end:
npm run install-local
this needs to be run with su priviledge. this command will take results of npm install, wrap them into egg file, deinstall previous version of dash-html-components and install a modified one.
or wait till @chriddyp reviews the change and releases new version. hope wont take long.
My solution to this is to maintain click state for all buttons in a hidden div “clicked-button” then use this to determine which button was last clicked. The example below has three buttons delete, add and toggle.
Thank you for this maral! I was trying to get something like this working using a similar strategy but didn’t realize that the State was different than the Input nor that the children had to be in string format!
Also see that you initialized n_clicks = 0, was having problems with “None” as the first entry. Lots to learn from this going forward!
The n_clicks_timestamp property is available for all elements in dash-html-components. We still need a solution that’s generally available for _all_components and all properties, but this is a start.
Thanks for doing this change! finally i can upgrade to the latest dash-html-components.
One comment though, this approach is inferior to using n_clicks_previous. If you combine multiple n_clicks, n_clicks_timestamp and other inputs, then on other inputs change you wont be able to say whether button was clicked or not. Timestamps will still indicate which button was clicked latest, but change could come from other input. n_clicks_previous was very deterministic and would allow to to positively say that change in the input came from button and which one.
still, for most of the purposes n_clicks_timestamp works.
Sir, I can’t use n_clicks_time-stamp for other html components like, radio button or slide bar. It shows error-
TypeError: Unexpected keyword argument `n_clicks_timestamp’
Sorry sir, Issue resolved , I am trying it on dash_core_components. My bad
Agree here with n_click_timestamps being a stop gap solution which only works if all inputs are buttons. I have a hack which works when mixed with one other input by comparing the time-stamp to the current time (as opposed to each other) but that relies on a threshold which depends on latency between user and server… I’m going to look into using the hidden div trick for now.
Would be great to see dash properly fix the issue of multiple triggering inputs or allowing multiple callbacks with same output!
Hi,
Thanks for providing the solution. I tried to use this function and it fixed my problem. But after running on a server for certain time, it give an error saying out of memory and crashed. Does the `n_clicks_timestamp’ just simply keep increasing? Thanks!
I ran into an issue whether I had to check whether a callback responded to a dcc.dropdown selection or a html.button click.
In the end I managed to get it to work by saving n_clicks in a hidden Div, and then loading this as a State n_clicks_previous. Then if n_clicks>n_clicks_previous I assume the button was pressed.
(basically a work around way of implementing the n_clicks_previous feature that was supposed to be implemented but no longer is?)
Hello Zoohair!
I have this same problem, trying to find whether a button or other inputs (‘children’ of divs in my case) triggered the callback.
Could you share your solution using current-time please?
Thanks!
Lionel
This is my solution: Note that I was using this on a local machine, and I’ve seen some oddities when it’s running on a server (timestamps might be using different t0, or the latency is more than I expected?)
Also this only works with one non-button event, I haven’t figured out how to do it with multiple ones.
@app.callback(
Output('configMapInputs', 'children'),
[Input('ResetClick', 'n_clicks_timestamp'),
Input('UndoClick', 'n_clicks_timestamp'),
Input('inputMap', 'selectedData')])
def serializeConfig(reset_time_ms, undo_time_ms,
selectedData):
#Hack to figure out what triggered this callback
#Keep this here as the thresholds below
#are based on assuming no computation is being done
#in this callback before the deltas are computed
curr_time_ms = time.time()*1e3
reset_time_ms = 0 if not reset_time_ms else reset_time_ms
undo_time_ms = 0 if not undo_time_ms else undo_time_ms
reset_time_ms = curr_time_ms - reset_time_ms
undo_time_ms = curr_time_ms - undo_time_ms
latency_thres = 500 #threshold between event being clicked and received at server
if reset_time_ms < latency_thres:
inputDists.clear()
elif undo_time_ms < latency_thres:
if len(inputDists) > 0: inputDists.pop()
elif selectedData != None:
newDist = None
wouldn’t a better option here be to create a radioButton object that works exactly like dcc.RadioItems but looks like buttons. I was optimistic that dbc.ButtonGroup was going to work like this but it doesn’t. It just does a tad better formatting them together. My control has a ButtonGroup of 12 or 20 buttons so distinguishing against all the timestamps to see whether one or none of the buttons was pressed is a genuine headache and waste of CPU. I could use tabs but don’t want to. I am probably forced to use RadioItems (really don’t want to). I need a simple working ButtonGroup :o?