Daily Tips - Share the Function 👪

Hi there,

Today’s tips are just a few words.

Only write the same logic once when using client-side callbacks, while regular callbacks must have a corresponding decorated function due to the use of decorators.

As in Chris’ reply, you can construct regular callbacks without decorators.

app.clientside_callback(
    ClientsideFunction(namespace='clientside', function_name='the_same_func'),
    Output(1, ''),
    Input(1, ''))

app.clientside_callback(
    ClientsideFunction(namespace='clientside', function_name='the_same_func'),
    Output(2, ''),
    Input(2, ''))
window.dash_clientside = Object.assign({}, window.dash_clientside, {
    clientside: {
        the_same_func: () => do_something()
    }
});

Hope this helps you. XD

Keywords: Client-side Callbacks

1 Like

Same tip can apply for regular functions too!

def update(value):
     …

# callback 1
callback(Output(…), Input(…))(update)

# callback 2
callback(Output(…), Input(…))(update)


4 Likes

hi @chriddyp ,
Forgive me, I forgot about the pointer things. So I can actually write lambda here too?

like

app.callback()(lambda x,y : x+y)

update:
I’ve tried. It works.

2 Likes