When any option is selected from any one dropdown, I want that same option removed from all other dropdowns.
To help visualize this, I'm trying to build a column mapper. For each column name on the left, there's a dropdown to the right where a user will select the column name from the file they have uploaded that corresponds to the name on the left. Since the source and destination columns have a one-to-one relationship, when a column name is selected from one of the dropdowns, it can be removed from all the other ones.
As a proof of concept, I tried this on just one of the dropdowns using the code below. When I select an option from any of the other dropdowns, I expect the option to be removed from this particular one. I don't get any errors and the callback appears in the callback graph, but it doesn't do anything. The print statements in the callback don't even run, which means the callback isn't actually running at all.
def generate_output_callback(input_id):
def dd_callback(input_values, state):
if not input_values:
print('Preventing update.'.upper())
raise PreventUpdate
else:
print(f'callback ran for dropdown {input_id}')
for val in input_values:
if val:
try:
i = state.index({'label': val, 'value': val})
del state[i]
except ValueError:
pass
return state
return dd_callback
all_cols = ['ACCTNUMBER', 'col2', 'col3']
inputs = {}
for col in all_cols:
inputs[col] = Input(col, 'value')
all_other_inputs_dict = {k:v for (k,v) in inputs.items() if k != 'ACCTNUMBER'}
all_other_inputs = list(all_other_inputs_dict.values())
cb = generate_output_callback('ACCTNUMBER')
app.callback(
Output('ACCTNUMBER', 'options'),
all_other_inputs,
[State('ACCTNUMBER', 'options')])(cb)