How to detect that a callback is fired by other one in chain?

I made a callback chain where:

  1. First callback fills layout component values in
  2. Second callback handles these values

The problem is when the first calls the second i can’t detect it, handling a call has to happen on a user input only.

I would like to find something like:

@callback(Output('shared-component', 'value'),
          Input('input' ,'value'))
def first_cbk():
    fill_shared_component_values()


@callback(Output('text component', 'chidlren',
          Input('shared-component', 'value')))
def  second_cbk():
    if not ctx.triggered_in_chain:
         handle()

Hello @kvdm.dev,

I would have different inputs, one for user input and the other for the callback.

Using the ctx you can know which triggered it, and which value gets used.

Well, i simply make a RangeSlider with date values in a user scope.
So i have to:

  1. Create a blank RangeSlider
  2. Log in
  3. Read user data
  4. Fill the RangeSlider values in with this data
  5. Handle the RangeSLider values update

Only one input has to be formed in the scenario.
Step 4 trigger steps 5 and it looks like as a user input, but it isn’t. The behavior is unfortunate as i create events on every user action.

Is there any flag on subject without workaround?

You could have a div that gets populated the first time the slider gets set, then use that state of true to determine that the user set the changes instead of the callback.

Ok, i think i get the idea, but could you give any example or a link to it?

Sure.

@callback(Output('shared-component', 'value'), 
          Input('input' ,'value'))
def first_cbk():
    fill_shared_component_values()
    return v


@callback(Output('text component', 'chidlren', Output('testing','children'),
          Input('shared-component', 'value'), State('testing','children')))
def  second_cbk(v, s):
    if s:
         handle(), dash.no_update
    else:
        return dash.no_update, True

Or something along these lines, where testing is a div with no children in your layout.

1 Like

I actually ended up with a server side flags storage to avoid problems with the race condition and etc as the way you suggested is sending states.

Thank you.

As long as you get something that works. :grin: