Skip to content
Merged
17 changes: 14 additions & 3 deletions dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def callback(
on_error: Optional[Callable[[Exception], Any]] = None,
api_endpoint: Optional[str] = None,
optional: Optional[bool] = False,
hidden: Optional[bool] = False,
hidden: Optional[bool] = None,
**_kwargs,
) -> Callable[..., Any]:
"""
Expand Down Expand Up @@ -181,6 +181,7 @@ def callback(
config_prevent_initial_callbacks = _kwargs.pop(
"config_prevent_initial_callbacks", False
)
config_hide_all_callbacks = _kwargs.pop("config_hide_all_callbacks", False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are those actually insert when using @callback directly? I think we need a better system for those since we want the same behavior for both @app.callback and @callback.

Think you can refactor these config into a context and use the context instead of passing them around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are those actually insert when using @callback directly? I think we need a better system for those since we want the same behavior for both @app.callback and @callback.

Think you can refactor these config into a context and use the context instead of passing them around?

Yes, similarly, for prevent_initial_callbacks, the callback functions defined by dash.callback() cannot obtain the setting values from dash.Dash() too.

callback_map = _kwargs.pop("callback_map", GLOBAL_CALLBACK_MAP)
callback_list = _kwargs.pop("callback_list", GLOBAL_CALLBACK_LIST)

Expand Down Expand Up @@ -222,6 +223,7 @@ def callback(
callback_list,
callback_map,
config_prevent_initial_callbacks,
config_hide_all_callbacks,
*_args,
**_kwargs,
background=background_spec,
Expand Down Expand Up @@ -253,6 +255,7 @@ def clientside_callback(clientside_function: ClientsideFuncType, *args, **kwargs
GLOBAL_CALLBACK_LIST,
GLOBAL_CALLBACK_MAP,
False,
False,
GLOBAL_INLINE_SCRIPTS,
clientside_function,
*args,
Expand All @@ -265,6 +268,7 @@ def insert_callback(
callback_list,
callback_map,
config_prevent_initial_callbacks,
config_hide_all_callbacks,
output,
outputs_indices,
inputs,
Expand All @@ -277,11 +281,14 @@ def insert_callback(
dynamic_creator: Optional[bool] = False,
no_output=False,
optional=False,
hidden=False,
hidden=None,
):
if prevent_initial_call is None:
prevent_initial_call = config_prevent_initial_callbacks

if hidden is None:
hidden = config_hide_all_callbacks

_validate.validate_duplicate_output(
output, prevent_initial_call, config_prevent_initial_callbacks
)
Expand Down Expand Up @@ -600,6 +607,7 @@ def register_callback(
callback_list,
callback_map,
config_prevent_initial_callbacks,
config_hide_all_callbacks,
*_args,
**_kwargs,
):
Expand Down Expand Up @@ -639,6 +647,7 @@ def register_callback(
callback_list,
callback_map,
config_prevent_initial_callbacks,
config_hide_all_callbacks,
insert_output,
output_indices,
flat_inputs,
Expand All @@ -651,7 +660,7 @@ def register_callback(
running=running,
no_output=not has_output,
optional=_kwargs.get("optional", False),
hidden=_kwargs.get("hidden", False),
hidden=_kwargs.get("hidden"),
)

# pylint: disable=too-many-locals
Expand Down Expand Up @@ -836,6 +845,7 @@ def register_clientside_callback(
callback_list,
callback_map,
config_prevent_initial_callbacks,
config_hide_all_callbacks,
inline_scripts,
clientside_function: ClientsideFuncType,
*args,
Expand All @@ -847,6 +857,7 @@ def register_clientside_callback(
callback_list,
callback_map,
config_prevent_initial_callbacks,
config_hide_all_callbacks,
output,
None,
inputs,
Expand Down
12 changes: 12 additions & 0 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ class Dash(ObsoleteChecker):
those callbacks you wish to have an initial call. This setting has no
effect on triggering callbacks when their inputs change later on.

:param hide_all_callbacks: Default ``False``: Sets the default value of
``hidden`` for all callbacks added to the app. Normally all callbacks
are visible in the devtools callbacks tab. You can set this for
individual callbacks by setting ``hidden`` in their definitions, or set
it ``True`` here in which case you must explicitly set it ``False`` for
those callbacks you wish to remain visible in the devtools callbacks tab.

:param show_undo_redo: Default ``False``, set to ``True`` to enable undo
and redo buttons for stepping through the history of the app state.
:type show_undo_redo: boolean
Expand Down Expand Up @@ -457,6 +464,7 @@ def __init__( # pylint: disable=too-many-statements
external_stylesheets: Optional[Sequence[Union[str, Dict[str, Any]]]] = None,
suppress_callback_exceptions: Optional[bool] = None,
prevent_initial_callbacks: bool = False,
hide_all_callbacks: bool = False,
show_undo_redo: bool = False,
extra_hot_reload_paths: Optional[Sequence[str]] = None,
plugins: Optional[list] = None,
Expand Down Expand Up @@ -537,6 +545,7 @@ def __init__( # pylint: disable=too-many-statements
"suppress_callback_exceptions", suppress_callback_exceptions, False
),
prevent_initial_callbacks=prevent_initial_callbacks,
hide_all_callbacks=hide_all_callbacks,
show_undo_redo=show_undo_redo,
extra_hot_reload_paths=extra_hot_reload_paths or [],
title=title,
Expand Down Expand Up @@ -671,6 +680,7 @@ def _setup_hooks(self):
self._callback_list,
self.callback_map,
self.config.prevent_initial_callbacks,
self.config.hide_all_callbacks,
self._inline_scripts,
clientside_function,
*args,
Expand Down Expand Up @@ -1433,6 +1443,7 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
self._callback_list,
self.callback_map,
self.config.prevent_initial_callbacks,
self.config.hide_all_callbacks,
self._inline_scripts,
clientside_function,
*args,
Expand All @@ -1456,6 +1467,7 @@ def callback(self, *_args, **_kwargs) -> Callable[..., Any]:
return _callback.callback(
*_args,
config_prevent_initial_callbacks=self.config.prevent_initial_callbacks,
config_hide_all_callbacks=self.config.hide_all_callbacks,
callback_list=self._callback_list,
callback_map=self.callback_map,
callback_api_paths=self.callback_api_paths,
Expand Down