Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Better Callback Context #1818

Closed
AnnMarieW opened this issue Oct 25, 2021 · 1 comment
Closed

[Feature Request] Better Callback Context #1818

AnnMarieW opened this issue Oct 25, 2021 · 1 comment
Labels
good first issue suitable for newcomers

Comments

@AnnMarieW
Copy link
Collaborator

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?!

@chriddyp chriddyp added the good first issue suitable for newcomers label Feb 10, 2022
@alexcjohnson
Copy link
Collaborator

Closed by @AnnMarieW in #1952 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue suitable for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants