# Clientside Callbacks equivalent for dash\_callback context

**URL:** <https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305>\
**Category:** Dash Python\
**Created:** [September 27, 2019, 9:51am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305 "2019-09-27T09:51:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![codefour](https://avatars.discourse-cdn.com/v4/letter/c/ea5d25/32.png) [@codefour](https://community.plotly.com/u/codefour)\
**Post date:** [September 27, 2019, 9:51am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/1 "2019-09-27T09:51:25Z")

</div>

Hello

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

If I have

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

            ]
        )

```

and

```auto
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

---

<div class="post-metadata">

**Author:** ![nicoco](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@nicoco](https://community.plotly.com/u/nicoco)\
**Post date:** [April 27, 2020, 1:24am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/2 "2020-04-27T01:24:01Z")

</div>

Any solution to this?

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [April 27, 2020, 2:49pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/3 "2020-04-27T14:49:17Z")

</div>

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](https://github.com/plotly/dash/issues/1213)

---

<div class="post-metadata">

**Author:** ![nicoco](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@nicoco](https://community.plotly.com/u/nicoco)\
**Post date:** [April 30, 2020, 5:13am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/4 "2020-04-30T05:13:51Z")

</div>

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/…

---

<div class="post-metadata">

**Author:** ![Emil](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emil/32/31734_2.png) [@Emil](https://community.plotly.com/u/Emil)\
**Post date:** [April 30, 2020, 5:19am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/5 "2020-04-30T05:19:57Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![nicoco](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@nicoco](https://community.plotly.com/u/nicoco)\
**Post date:** [April 30, 2020, 5:51am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/6 "2020-04-30T05:51:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Atishya](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Atishya](https://community.plotly.com/u/Atishya)\
**Post date:** [June 11, 2020, 4:40am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/7 "2020-06-11T04:40:27Z")

</div>

Is this feature added in dash==1.12.0 ?  
I cant see any field “triggered” or even “callback\_context” inside “dash\_clientside”

---

<div class="post-metadata">

**Author:** ![suiroc](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@suiroc](https://community.plotly.com/u/suiroc)\
**Post date:** [June 18, 2020, 11:53am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/8 "2020-06-18T11:53:11Z")

</div>

Have a look [here](https://github.com/plotly/dash/releases) - it was just released! 😄

---

<div class="post-metadata">

**Author:** ![nhoover](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nhoover/32/13282_2.png) [@nhoover](https://community.plotly.com/u/nhoover)\
**Post date:** [March 19, 2021, 4:03pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/10 "2021-03-19T16:03:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielcahall](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@danielcahall](https://community.plotly.com/u/danielcahall)\
**Post date:** [November 22, 2021, 1:13pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/11 "2021-11-22T13:13:34Z")

</div>

Just to be clear (since the answer marked “Solution” points to the Github releases page), this feature was released in [1.13](https://github.com/plotly/dash/releases/tag/v1.13).

---

<div class="post-metadata">

**Author:** ![JZbinden](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@JZbinden](https://community.plotly.com/u/JZbinden)\
**Post date:** [December 6, 2022, 1:48pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/12 "2022-12-06T13:48:41Z")

</div>

Adding the associated [forum release post for v1.13](https://community.plotly.com/t/dash-v1-13-3-release-improved-performance-clientside-callback-context-many-dcc-graph-datatable-bug-fixes/41247) since it’s one of the top results.

From the release post:

```auto
window.dash_clientside.callback_context
window.dash_clientside.callback_context.triggered
window.dash_clientside.callback_context.inputs
window.dash_clientside.callback_context.inputs_list
window.dash_clientside.callback_context.states
window.dash_clientside.callback_context.states_list

```

---

<div class="post-metadata">

**Author:** ![Amazigh](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/amazigh/32/19636_2.png) [@Amazigh](https://community.plotly.com/u/Amazigh)\
**Post date:** [September 20, 2023, 7:12pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/13 "2023-09-20T19:12:27Z")

</div>

is there an equivalent to ctx.outputs\_list

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [September 21, 2023, 12:57am UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/14 "2023-09-21T00:57:05Z")

</div>

The callback context applies just to the Inputs. What are you trying to do with the callback outputs?

---

<div class="post-metadata">

**Author:** ![Amazigh](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/amazigh/32/19636_2.png) [@Amazigh](https://community.plotly.com/u/Amazigh)\
**Post date:** [September 21, 2023, 1:02pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/15 "2023-09-21T13:02:17Z")

</div>

Thank you @AnnMarieW for the quick reply 🙂

I was trying to use the same logic below in the client-side callback but could not find the equivalent of ctx.outputs\_list. buy the way there isn’t the equivalent of ctx.triggered\_id witch would make the code a bit cleaner.

```auto
@app.callback(
    Output({"type": "page_layout_id", "index": ALL}, "style"), 
    Output({"type": "page_switcher_action", "index": ALL}, "style"),
    Output({"type": "page_switcher_action_text", "index": ALL}, "style"),
    Input({"type": "page_switcher_action", "index": ALL}, "n_clicks"),
    prevent_initial_call=True
)

def page_switcher(action_click):
    print(ctx.outputs_list[0])
    triggered_input = ctx.triggered_id['index']
    output_list = [i['id']['index'] for i in ctx.outputs_list[0]]
    print(output_list)
    number_of_outputs, triggered_input_index = len(output_list), output_list.index(triggered_input)
    page_output_list = [{'display':'none'}] * number_of_outputs
    action_item_output_list = [{}] * number_of_outputs
    page_output_list[triggered_input_index] = {'display':'block'}
    action_item_output_list[triggered_input_index] = {'color':'rgb(34, 139, 230)'}

    return page_output_list, action_item_output_list, action_item_output_list

```

here is how i ended up converting the above serverside call back into clientside callback.

```auto
page_switcher: function(page_switcher_input) {
    ctx = window.dash_clientside.callback_context;
 
    pages_list = ctx.inputs_list[0];
    triggered_input = JSON.parse(ctx.triggered[0].prop_id.replace(".n_clicks", "")).index
    let output_list = []
    pages_list.forEach((page) => output_list.push(page.id.index));
    let number_of_pages = output_list.length
    let triggered_input_index = output_list.indexOf(triggered_input)

    let page_output_list = Array(number_of_pages).fill({'display':'none'})
    let action_item_output_list = Array(number_of_pages).fill({})
    page_output_list[triggered_input_index] = {'display':'block'}
    action_item_output_list[triggered_input_index] = {'color':'rgb(34, 139, 230)'}
    console.log(page_output_list, action_item_output_list);
  
    return [page_output_list, action_item_output_list, action_item_output_list];
}

```

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [September 21, 2023, 3:02pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/16 "2023-09-21T15:02:57Z")

</div>

Hi @Amazigh

It appears that you are trying to switch pages of a multi page app, Have you tried [Dash Pages](https://dash.plotly.com/urls)? Another option is to use the Tabs component with the content as tab children. Then the component itself will handle displaying the pages, no callback required. A third option is to use MATCH instead of ALL

---

<div class="post-metadata">

**Author:** ![Amazigh](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/amazigh/32/19636_2.png) [@Amazigh](https://community.plotly.com/u/Amazigh)\
**Post date:** [September 21, 2023, 3:57pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/17 "2023-09-21T15:57:35Z")

</div>

I initially started with MATCH. Here’s what I struggled with: in the provided code, there are two callbacks. The commented one uses ALL and it functions correctly. The other one is where I attempted to use MATCH, but what I couldn’t achieve was hiding the other pages upon clicking. Below is the complete code "

```auto

from dash import Dash, dcc, html, Input, Output, ALL, MATCH, callback, ctx, no_update
from dash_iconify import DashIconify as icon
import dash_mantine_components as dmc

app = Dash(
    __name__ ,
    external_stylesheets=[
        "https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;900&display=swap"
    ],
)

footer_icon_with = 30
footer_icon_color = '#A519C7'

def id_dict (_id, index):
    return {"type": f"{_id}", "index":f"{index}"}

def footer_action_link (_id, _index, _icon, is_default=False):
    icon_text_size = 'xs'
    icon_and_text_color = {}
    if is_default:
        icon_and_text_color = {'color':'rgb(34, 139, 230)'}

    return dmc.Center(
                children = [
                    dmc.Stack(
                        align="center",
                        children = [
                            dmc.ActionIcon(
                                id = id_dict (f'{_id}', _index),
                                variant='transparent',  
                                style = icon_and_text_color,
                                children = [
                                    icon(icon=_icon, width = footer_icon_with)
                                ]
                            ),
                            dmc.Text("Shop", size=icon_text_size, style = icon_and_text_color, id = id_dict (f'{_id}_text', _index)),
                        ]
                    )
                ]
            ) 
    
footer = dmc.Paper(
    style= {'position': 'fixed', 'bottom':'0', 'width': '450px'},
    children =[
        dmc.Group(
            position = 'apart',
            children = [
                footer_action_link ("page_switcher_action", "shop", 'tabler:shopping-bag', is_default=True),
                footer_action_link ("page_switcher_action", "account", 'ic:sharp-person-outline'),
                footer_action_link ("page_switcher_action", "cart", 'ic:outline-shopping-cart')
            ]
        ),
        
    ]
)

shop = dmc.Paper(
    id = id_dict('page_layout_id', 'shop'),
    style = {'display':'block'},
    className = 'page',
    children = [
        dmc.Text("cart_page", size="md", color ='blue'),

    ]
)

account = dmc.Paper(
    id = id_dict('page_layout_id', 'account'),
    className = 'page',
    style = {'display':'none'},
    children = [
        dmc.Text("account_page", size="md", color ='yellow'),
    ]
)

cart = dmc.Paper(
    id = id_dict('page_layout_id', 'cart'),
    style = {'display':'none'},
    className = 'page',
    children = [
        dmc.Text("cart_page", size="md", color ='blue'),

    ]
)
content = dmc.Container(
    className = 'content',
    children = [
        shop,
        account,
        cart,
    ]
)
   
app.layout = html.Div(
    style={"height": 930, "width": 450, 'border': '2px solid red', 'overflow':'scroll'},
    children=[
        html.Div(
            children = [
                content,
                footer
            ]
        )
    ]

)

# @app.callback(
# Output({"type": "page_layout_id", "index": ALL}, "style"), 
# Output({"type": "page_switcher_action", "index": ALL}, "style"),
# Output({"type": "page_switcher_action_text", "index": ALL}, "style"),
# Input({"type": "page_switcher_action", "index": ALL}, "n_clicks"),
# prevent_initial_call=True
# )

# def page_switcher(action_click):
# print(ctx.outputs_list[0])
# triggered_input = ctx.triggered_id['index']
# output_list = [i['id']['index'] for i in ctx.outputs_list[0]]
# print(output_list)
# number_of_outputs, triggered_input_index = len(output_list), output_list.index(triggered_input)
# page_output_list = [{'display':'none'}] * number_of_outputs
# action_item_output_list = [{}] * number_of_outputs
# page_output_list[triggered_input_index] = {'display':'block'}
# action_item_output_list[triggered_input_index] = {'color':'rgb(34, 139, 230)'}

# return page_output_list, action_item_output_list, action_item_output_list

@app.callback(
    Output({"type": "page_layout_id", "index": MATCH}, "style"), 
    Input({"type": "page_switcher_action", "index": MATCH}, "n_clicks"),
    prevent_initial_call=True
)

def page_switcher(action_click):
  
    return {'display':'block'}

if __name__ == " __main__":
    app.run_server(debug=True, host='0.0.0.0', port=8050 )

```

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [September 21, 2023, 4:33pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/18 "2023-09-21T16:33:14Z")

</div>

Hi @Amazigh - Before digging into this, can you say why Pages or Tabs won’t work for you? It would be a much easier solution.

---

<div class="post-metadata">

**Author:** ![Amazigh](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/amazigh/32/19636_2.png) [@Amazigh](https://community.plotly.com/u/Amazigh)\
**Post date:** [September 21, 2023, 5:15pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/19 "2023-09-21T17:15:44Z")

</div>

I prefer not to utilize pages since I aim to avoid making server calls for page switching. Unfortunately, dmc.Tabs lacks an option to position the navigation at the bottom. The provided code offers a workaround using ALL, but I’m keen to explore your suggestion of using MATCH, which would be a cleaner approach and an opportunity to explore another practical application for MATCH.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [September 21, 2023, 9:36pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/20 "2023-09-21T21:36:48Z")

</div>

Hello @Amazigh,

Have you looked into my page layout caching?

This loads everything to cache from the server and then caters the responses from the cache.

> [@Page Layout Caching](https://community.plotly.com/t/page-layout-caching/77237):
>
> Good day, All, With my use of the Dash app, I encountered an issue where I wanted the page layouts to be cached clientside. This is different from caching on the server side, as there is no need to allow the request to event leave the client’s computer. I wanted this because I have semi-dynamic layouts that are costly to run, but dont need to be run every time the user loads the page. In fact, these layouts hardly need to change except for when I make a coding change. Thus, I took a stab at b…

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [September 21, 2023, 10:07pm UTC](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305/21 "2023-09-21T22:07:37Z")

</div>

It looks like the latest release of Dash Mantine Components will have Tabs with the navigation on the bottom.

> **[Tabs | Mantine](https://mantine.dev/core/tabs/#inverted-tabs)**
>
> Switch between different views

[Next page](https://community.plotly.com/t/clientside-callbacks-equivalent-for-dash-callback-context/29305.md?page=2)
