To describe what I am trying to do, consider the below UI
- Card(s) are bootstrap card components.
- It has ‘X’ button to delete the card from the container named ‘body-container’
- It has ‘↑’ button to move the card up in the container. Just like Jupyter notebook, where we move cell up or down
- It has ‘↓’ button to move cell down
Now I have implemented all this as clientside callbacks for some specific reasons and speed and can’t make it server-side.
Now, there is one dropdown, user can select a specific element from the dropdown and that ‘Card’ will be added into the ‘body-container’ children. Now I have all the components as a python dict just like mentioned here. Now How can I integrate this code? I can not write server side callback because dash won’t allow me duplicate callback output for Output('body-container', 'children')
. How to resolver this issue?
Here is a pseudo code–
Cards = {
'card A': CardA(),
'card B': CardB(),
'card C': CardC(),
}
app.clientside_callback(
"""
function(n_clicks_1, n_clicks_2, n_clicks_3, children) {
// javascript code
// some operation on children
return children;
}
""",
Output('body-container', 'children'),
[Input({'type': 'delete-card', 'id': ALL}, 'n_clicks'),
Input({'type': 'down-card', 'id': ALL}, 'n_clicks'),
Input({'type': 'up-card', 'id': ALL}, 'n_clicks')],
State('body-container', 'children'),
prevent_initial_call=True
)
@app.callback(
Output('body-container', 'children'),
Input('main-app-dropdown', 'value'),
State('body-container', 'children'),
prevent_initial_call=True
)
def add_card_to_body(value, children):
# return a spcific child
# get desired card from Card dictionary
children.append(child_I_want_to_add)
return children