Skip to content

[Feature Request] Better Callback Context #1818

Closed

Description

@AnnMarieW

As suggested by @chriddyp in this forum post: creating a new triggered_dict would remove some boilerplate and make it possible to have more readable and intuitive code when using the callback_context

provide a more ergonomic:

triggered_id = callback_context.triggered[0]['prop_id']

For example, we could make a new triggered_dict that would have the same content but be a dictionary instead of a list. The logic would become:

def update_graph(b1, b2):
    if 'reset.n_clicks' in dash.callback_context.triggered_map:
        return reset_graph()
    elif 'draw.n_clicks'  in dash.callback_context.triggered_map:
        return draw_graph()

It would also be great to address PMC as well. See this this forum post:

Is there any good practice for parsing callback_context ? I recently started working more with pattern-matching callbacks and extracting certain values from the callback_context became essential. Until today, I have been doing things such as

idx = callback_context.states['packaging_concepts-div-waste_items.children'][-2]['props']['id']['index']

😬 😬

There must be a better way! Right?!

Activity

  1. alexcjohnson commented on Apr 22, 2022

    @alexcjohnson
    Collaborator

    Closed by @AnnMarieW in #1952 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions