Skip to content

Commit 36c7171

Browse files
authored
Merge pull request #3407 from plotly/hidden-callbacks
Add hidden callbacks.
2 parents a2ed613 + 20634cc commit 36c7171

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
77
## Added
88
- [#3395](https://github.com/plotly/dash/pull/3396) Add position argument to hooks.devtool
99
- [#3403](https://github.com/plotly/dash/pull/3403) Add app_context to get_app, allowing to get the current app in routes.
10+
- [#3407](https://github.com/plotly/dash/pull/3407) Add `hidden` to callback arguments, hiding the callback from appearing in the devtool callback graph.
1011

1112
## Fixed
1213
- [#3395](https://github.com/plotly/dash/pull/3395) Fix Components added through set_props() cannot trigger related callback functions. Fix [#3316](https://github.com/plotly/dash/issues/3316)

dash/_callback.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _invoke_callback(func, *args, **kwargs): # used to mark the frame for the d
6464
GLOBAL_INLINE_SCRIPTS = []
6565

6666

67-
# pylint: disable=too-many-locals
67+
# pylint: disable=too-many-locals,too-many-arguments
6868
def callback(
6969
*_args,
7070
background: bool = False,
@@ -78,6 +78,7 @@ def callback(
7878
cache_ignore_triggered=True,
7979
on_error: Optional[Callable[[Exception], Any]] = None,
8080
optional: Optional[bool] = False,
81+
hidden: Optional[bool] = False,
8182
**_kwargs,
8283
) -> Callable[..., Any]:
8384
"""
@@ -162,6 +163,8 @@ def callback(
162163
to access the original callback inputs, states and output.
163164
:param optional:
164165
Mark all dependencies as not required on the initial layout checks.
166+
:param hidden:
167+
Hide the callback from the devtools callbacks tab.
165168
"""
166169

167170
background_spec = None
@@ -217,6 +220,7 @@ def callback(
217220
running=running,
218221
on_error=on_error,
219222
optional=optional,
223+
hidden=hidden,
220224
)
221225

222226

@@ -263,6 +267,7 @@ def insert_callback(
263267
dynamic_creator: Optional[bool] = False,
264268
no_output=False,
265269
optional=False,
270+
hidden=False,
266271
):
267272
if prevent_initial_call is None:
268273
prevent_initial_call = config_prevent_initial_callbacks
@@ -287,6 +292,7 @@ def insert_callback(
287292
"dynamic_creator": dynamic_creator,
288293
"no_output": no_output,
289294
"optional": optional,
295+
"hidden": hidden,
290296
}
291297
if running:
292298
callback_spec["running"] = running
@@ -631,6 +637,7 @@ def register_callback(
631637
running=running,
632638
no_output=not has_output,
633639
optional=_kwargs.get("optional", False),
640+
hidden=_kwargs.get("hidden", False),
634641
)
635642

636643
# pylint: disable=too-many-locals

dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function generateElements(graphs, profile, extraLinks) {
7878
});
7979
}
8080

81-
(graphs.callbacks || []).forEach((callback, i) => {
81+
(graphs.callbacks || []).reduce((visibleIndex, callback) => {
82+
if (callback.hidden) {
83+
return visibleIndex;
84+
}
85+
8286
const cb = `__dash_callback__.${callback.output}`;
8387
const cbProfile = profile.callbacks[callback.output] || {};
8488
const count = cbProfile.count || 0;
@@ -87,7 +91,7 @@ function generateElements(graphs, profile, extraLinks) {
8791
elements.push({
8892
data: {
8993
id: cb,
90-
label: `callback.${i}`,
94+
label: `callback.${visibleIndex}`,
9195
type: 'callback',
9296
mode: callback.clientside_function ? 'client' : 'server',
9397
count: count,
@@ -97,21 +101,23 @@ function generateElements(graphs, profile, extraLinks) {
97101
}
98102
});
99103

100-
callback.outputs.map(({id, property}) => {
104+
callback.outputs.forEach(({id, property}) => {
101105
const nodeId = recordNode(id, property);
102106
recordEdge(cb, nodeId, 'output');
103107
});
104108

105-
callback.inputs.map(({id, property}) => {
109+
callback.inputs.forEach(({id, property}) => {
106110
const nodeId = recordNode(id, property);
107111
recordEdge(nodeId, cb, 'input');
108112
});
109113

110-
callback.state.map(({id, property}) => {
114+
callback.state.forEach(({id, property}) => {
111115
const nodeId = recordNode(id, property);
112116
recordEdge(nodeId, cb, 'state');
113117
});
114-
});
118+
119+
return visibleIndex + 1;
120+
}, 0);
115121

116122
// pull together props in the same component
117123
if (extraLinks) {

0 commit comments

Comments
 (0)