MCPcopy Index your code
hub / github.com/plotly/dash / CallbackContext

Class CallbackContext

dash/_callback_context.py:54–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53# pylint: disable=no-init
54class CallbackContext:
55 @property
56 @has_context
57 def inputs(self):
58 return getattr(_get_context_value(), "input_values", {})
59
60 @property
61 @has_context
62 def states(self):
63 return getattr(_get_context_value(), "state_values", {})
64
65 @property
66 @has_context
67 def triggered(self):
68 """
69 Returns a list of all the Input props that changed and caused the callback to execute. It is empty when the
70 callback is called on initial load, unless an Input prop got its value from another initial callback.
71 Callbacks triggered by user actions typically have one item in triggered, unless the same action changes
72 two props at once or the callback has several Input props that are all modified by another callback based on
73 a single user action.
74
75 Example: To get the id of the component that triggered the callback:
76 `component_id = ctx.triggered[0]['prop_id'].split('.')[0]`
77
78 Example: To detect initial call, empty triggered is not really empty, it's falsy so that you can use:
79 `if ctx.triggered:`
80 """
81 # For backward compatibility: previously `triggered` always had a
82 # value - to avoid breaking existing apps, add a dummy item but
83 # make the list still look falsy. So `if ctx.triggered` will make it
84 # look empty, but you can still do `triggered[0]["prop_id"].split(".")`
85 return getattr(_get_context_value(), "triggered_inputs", []) or falsy_triggered
86
87 @property
88 @has_context
89 def triggered_prop_ids(self):
90 """
91 Returns a dictionary of all the Input props that changed and caused the callback to execute. It is empty when
92 the callback is called on initial load, unless an Input prop got its value from another initial callback.
93 Callbacks triggered by user actions typically have one item in triggered, unless the same action changes
94 two props at once or the callback has several Input props that are all modified by another callback based
95 on a single user action.
96
97 triggered_prop_ids (dict):
98 - keys (str) : the triggered "prop_id" composed of "component_id.component_property"
99 - values (str or dict): the id of the component that triggered the callback. Will be the dict id for pattern matching callbacks
100
101 Example - regular callback
102 {"btn-1.n_clicks": "btn-1"}
103
104 Example - pattern matching callbacks:
105 {'{"index":0,"type":"filter-dropdown"}.value': {"index":0,"type":"filter-dropdown"}}
106
107 Example usage:
108 `if "btn-1.n_clicks" in ctx.triggered_prop_ids:
109 do_something()`
110 """
111 triggered = getattr(_get_context_value(), "triggered_inputs", [])

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…