✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Multiple callbacks to same output [Again]- this time with a datatable

Hi, I know that I can’t have multiple callbacks to the same output, but I’m confused about what to do in the meantime.

I have a datatable and want ability for users to either click on AddRow to append a row and then be able to type numbers in directly, or click on Upload to get a CSV and populate all in one go. I can do either one of these with a callback, but…

… what would be recomendations or hints to optimal solution?

You group all operations related to an output into one callback. In some cases this can make the code less readable, so I have written a small utility class DashCallbackBlueprint that takes care of it. Here is an example,

import dash
import dash_html_components as html
from dash.dependencies import Output, Input
from dash_extensions.callback import DashCallbackBlueprint

app = dash.Dash()
app.layout = html.Div([html.Button("Button 1", id="btn1"), html.Button("Button 2", id="btn2"), html.Div(id="div")])
dcb = DashCallbackBlueprint() 

@dcb.callback(Output("div", "children"), [Input("btn1", "n_clicks")])
def click_btn1(n_clicks):
    return "You clicked btn1"

@dcb.callback(Output("div", "children"), [Input("btn2", "n_clicks")]) 
def click_btn2(n_clicks):
    return "You clicked btn2"


if __name__ == '__main__':

Thanks, merging the callbacks did indeed solve the problem.