✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Control order of call backs

Here is my scenario:

  1. Drop down#1 have list of data frames to choose and user can choose only 1 dataframe
  2. Drop down#2 is dynamic and depending on the dataframe chose in dropdown#1, it’s columns get populated in this dropdown#2.
  3. Based on column/s selected in dropdown#2, I have some callbacks displaying graphs for the columns selected.

Now let’s say if the user chooses another dataframe without clearing the column/s selected in dropdown#2, I am getting error from the graph displaying callbacks as the predicting columns will not be there in the newly selected datafrane.

One if the solution is when user selected a dataframe from dropdown#1, I can write a callback to first clear the values in the dropdown#2 and another Callback to populate its columns. But how can I control the order of execution of these 2 call backs pointing to same output(values in dropdown#2).

You could make dropdown1 have the following callback

def populate_dropdown2(dropdown1_value):
    ... make options based on dropdown1_value ...
    return ("",options)

This will “clear” the second dropdown (it will display nothing) and send "" to the final callback, assuming the final callback has the input: Input('dropdown2','value').
With this, you have to make the final callback able to handle the case where it receives “” as an input (perhaps in this case, it just clears the plots or whatever). Also it doesn’t seem to matter the order of the specification of Outputs for the populate_dropdown2 callback: when the value is sent, it triggers the final callback, whereas setting the options doesn’t trigger the final callback, so they can be changed before or after value is sent. :bird:

@nickest Thank you, it worked.