Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Clientside Callbacks equivalent for dash_callback context

Hello

Is there any way to know what input triggered in a clientside callback?

If I have

 app.clientside_callback(
            ClientsideFunction(
                namespace='clientside',
                function_name=my_fun'
            ),
            Output('bla', "className"),
            [
                Input("Inp-1", "n_clicks"),
                Input("Inp-2", "n_clicks"),

            ]
        )

and

if(!window.dash_clientside) {window.dash_clientside = {};}

window.dash_clientside.clientside = {

    my_fun:(...args) => {
         ...

    }
}

I will not be able (?) to know which input triggered. Is there a way to know?

Love Clientside BTW!

Edit 1: Typo
Edit 2: Typo

2 Likes

Any solution to this?

This has not been implemented, but it’s definitely a good idea and there isn’t anything technical blocking it from happening (just development time!). GitHub issue here: https://github.com/plotly/dash/issues/1213

1 Like

Thank you very much for opening the issue @chriddyp!

I was wondering if there was an easy workaround in the meantime. I have a clientside callback that receives different button n_clicks events as inputs, and should behave differently depending on which button was responsible for the call. Is there an obvious way to implement that? My javascript skills are limited, and I have trouble following what is happening in the guts of react/dash/…

@nicoco - You can listen to n_clicks_timestamp (instead of n_clicks). By comparing the timestamps, you can get the trigger, i.e. the one with the latest timestamps.

2 Likes

Thank you for your answer! However, my problem is that not all inputs for this client side callback are buttons, one is storage data modifications, another one is graph clickData and in fact only one is an actual button. This is probably poor design on my side…

It gets even uglier, as a workaround, I made this callback output to n_clicks_timestamp of the button that triggers it and also receive n_click_timestamp as a State so that I can determine what actually called the callback. Yeah it is messy. It works ATM but looks unmaitainable, have to redesign this.

Is this feature added in dash==1.12.0 ?
I cant see any field “triggered” or even “callback_context” inside “dash_clientside”

Have a look here - it was just released! :smile:

1 Like

Great! So glad I found this. It works perfectly. Why isn’t this feature in the documentation? It’s been so many months.

1 Like

Just to be clear (since the answer marked “Solution” points to the Github releases page), this feature was released in 1.13.