I am building a table using dash bootstrap components as I would like to have a multi-select dropdown in the datatable. This works in, but when I try to trigger a callback based on my selection, the callback doesn’t fire. The table is created using the following code:
*note df = a dataframe of variable length with columns q_uuid and questions used to build the table which is loaded as an output child from a different callback following a button press.
@app.callback(Output("question_table_location","children"),
Input("load_button", "n_clicks"))
def load_output(load_b,instance_id):
############################
# Build HTML table
table_header = [
html.Thead(html.Tr([html.Th("Selected"),
html.Th("Question_UUID"),
html.Th("Question"),
html.Th("Category")]))]
table_row = []
for row in range(df.shape[0]):
temp_row = html.Tr([html.Td(dcc.Checklist(options=[{'label': '', 'value': 'Checked'}],
value=[''],
id=f'cb_{row}')),
html.Td(df.loc[row,'q_uuid']),
html.Td(df.loc[row,'question']),
html.Td([dcc.Dropdown(
[{"label": f"{vci}",
"value": vci} for vci in categories],
placeholder="Category",
id=f"cat_dd_{row}",
multi=True,
style={'width':'100%'})])])
table_row.append(temp_row)
table_body = [html.Tbody(table_row)]
table = dbc.Table(table_header + table_body, bordered=True,id='question-table',style={"width": "1400px"})
return table
because I have a variable number of dropdowns, I tried to set the output up as follows:
@app.callback(Output("select_all_button", "disabled"),
[Input(f"cat_dd_{row}","value") for row in range(df.shape[0])])
def select_row(*args):
button_id = ctx.triggered_id
print(button_id)
print(args)
return False
If I remove the callback the table builds fine, but with the callback things hang when I press the button to build the table.
Any suggestions would be appreciated!.