diff --git a/CHANGELOG.md b/CHANGELOG.md index de4049c614..b7dcd9c0b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## Added - [#3534]((https://github.com/plotly/dash/pull/3534) Adds `playsInline` prop to `html.Video`. Based on [#2338]((https://github.com/plotly/dash/pull/2338) - [#3541](https://github.com/plotly/dash/pull/3541) Add `attributes` dictionary to be be formatted on script/link (_js_dist/_css_dist) tags of the index, allows for `type="module"` or `type="importmap"`. [#3538](https://github.com/plotly/dash/issues/3538) +- [#3564](https://github.com/plotly/dash/pull/3564) Add new parameter `hide_all_callbacks` to `run()`. Closes [#3493](https://github.com/plotly/dash/issues/3493) ## Fixed - [#3541](https://github.com/plotly/dash/pull/3541) Remove last reference of deprecated `pkg_resources`. diff --git a/dash/_callback.py b/dash/_callback.py index fa41cde51f..0b63f17740 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -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]: """ @@ -277,7 +277,7 @@ 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 @@ -651,7 +651,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", None), ) # pylint: disable=too-many-locals diff --git a/dash/dash.py b/dash/dash.py index 749e38d107..95df01e64c 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -544,6 +544,7 @@ def __init__( # pylint: disable=too-many-statements include_pages_meta=include_pages_meta, description=description, health_endpoint=health_endpoint, + hide_all_callbacks=False, ) self.config.set_read_only( [ @@ -1646,6 +1647,16 @@ def _setup_server(self): self.callback_map[k] = _callback.GLOBAL_CALLBACK_MAP.pop(k) self._callback_list.extend(_callback.GLOBAL_CALLBACK_LIST) + + # For each callback function, if the hidden parameter uses the default value None, + # replace it with the actual value of the self.config.hide_all_callbacks. + self._callback_list = [ + {**_callback, "hidden": self.config.get("hide_all_callbacks", False)} + if _callback.get("hidden") is None + else _callback + for _callback in self._callback_list + ] + _callback.GLOBAL_CALLBACK_LIST.clear() _validate.validate_background_callbacks(self.callback_map) @@ -2293,6 +2304,7 @@ def run( port: Optional[Union[str, int]] = None, proxy: Optional[str] = None, debug: Optional[bool] = None, + hide_all_callbacks: bool = False, jupyter_mode: Optional[JupyterDisplayMode] = None, jupyter_width: str = "100%", jupyter_height: int = 650, @@ -2341,6 +2353,14 @@ def run( via ``run``. env: ``DASH_DEBUG`` :type debug: bool + :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. + :type hide_all_callbacks: bool + :param dev_tools_ui: Show the dev tools UI. env: ``DASH_UI`` :type dev_tools_ui: bool @@ -2407,6 +2427,10 @@ def run( :return: """ + + # Update self.config.hide_all_callbacks + self.config.update({"hide_all_callbacks": hide_all_callbacks}) + if debug is None: debug = get_combined_config("debug", None, False)