Problem
I figured out occasionally that if a callback returns a dynamic component that consists of subcomponents it can call another callback those subcomponents assigned to as Inputs.
Brief example
@callback(
Output('card-container', 'children'),
Input('button', n_clicks))
def add_card(n_clicks):
return dbc.Card(id=card_id,
children=[
dbc.Button(html.I(className="bi bi-pencil-square"),
id={'type': IdTypeEnum.BUTTON_OPEN.value, 'index': card_id})
dbc.Button(html.I(className="bi bi-archive"),
id={'type': IdTypeEnum.BUTTON_ARCHIVE.value, 'index': card_id})
]),
@callback(
Output('cytoscape', 'elements'),
Input('toggle', 'n_cliks')
Input({'type': IdTypeEnum.BUTTON_ARCHIVE.value, 'index': ALL}, 'n_clicks'),
Input({'type': IdTypeEnum.BUTTON_OPEN.value, 'index': ALL}, 'n_clicks'))
def handle_elements(n_clicks1, n_clicks2, n_clicks3)
print(ctx.triggered_id)
Due to the documentation i expect handle_elements
stay untouched as i didn’t declare Buttons as Output of the add_card
callback
Questions
- Has
handle_elements
to be called byadd_card
? is such the mechanic correct? - If it’s correct, can it be disabled or avoided somehow? i’d like to have the inputs triggered by a real user only, not by a callback chain.