I want to dynamically add columns based on selected dropdown values. I tried the example that is in Adding or removing columns section, but this works only when you try to add columns using a button.
My table is created also dynamically based on two dropdowns (I have a callback that returns the whole datatable definition).
My code for adding the columns:
@app.callback(
[Output(‘main_table’, ‘columns’)],
[Input(‘second_dropdown’, ‘value’)],
[State(‘main_data’, ‘data’), State(‘main_table’, ‘columns’)]
)
def add_columns(values, data, existing_columns):
if existing_columns is None:
return None
for value in values:
if value not in existing_columns:
existing_columns.append({
‘id’: value,
‘name’: value
})
print(existing_columns)
return existing_columns
I searched for something similar to my problem but I didn’t succeed.
I’m new to Dash so any kind of help would be really appriciated.