Hello, i am new to dash. i am trying to have keyboard key down for some specific keys in js. In the event it should access dcc.store and change the values.
in dash:
problem is, each time i press a arrow button, the event triggers one+the numer of times i already pressed. so in trird press the event will trigger 4 times. the reason is probably each time theupdate_selection_box function is called, it attaches a new keydown event listener without removing the previous ones. But I dont know how to solve this ?
This is because you are using the data as a callback, the callback only exists to add an event listener to the DOM element, you are adding an event listener to the element each time you are updating the data.
thanks for the reply. the localStorage and sessionStorage both are working after removing the clientside callback. One problem I still have is , after some keyboard operation new coords are saved in the local/session storage and then if I reload the page I get the following error message in the browser:
In the callback for output(s):
selection-coords.data@46d0580ef4cf90229cdf19676f2b3627
Output 0 (selection-coords.data@46d0580ef4cf90229cdf19676f2b3627) is already in use.
To resolve this, set `allow_duplicate=True` on
duplicate outputs, or combine the outputs into
one callback function, distinguishing the trigger
by using `dash.callback_context` if necessary.
but in the dash code i already made Output('selection-coords', 'data', allow_duplicate=True)
Ah, this is more than likely due to having the same inputs for both of the callbacks.
In dash, there is a serialization of the ids for the output to make sure that these can be called uniquely.
My way around this is to add an unused input, like the id of the component. Since if you are using prevent_initial_call=True this id doesnt trigger it.