From 675502f9ba97978267a92bc7910305a0f2e6d476 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Thu, 5 Dec 2024 12:20:25 +0000 Subject: [PATCH] POC for data_frame parameter --- .../src/vizro/actions/_actions_utils.py | 11 +++++----- .../src/vizro/actions/_parameter_action.py | 21 ++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/vizro-core/src/vizro/actions/_actions_utils.py b/vizro-core/src/vizro/actions/_actions_utils.py index 1873b6620..ed776976f 100644 --- a/vizro-core/src/vizro/actions/_actions_utils.py +++ b/vizro-core/src/vizro/actions/_actions_utils.py @@ -257,13 +257,14 @@ def _get_modified_page_figures( outputs: dict[ModelID, Any] = {} - control_targets = [] - figure_targets = [] + control_targets = set() + figure_targets = set() for target in targets: - if isinstance(model_manager[target], Filter): - control_targets.append(target) + if isinstance((filter := model_manager[target]), Filter): + control_targets.add(target) + figure_targets |= set(filter.targets) else: - figure_targets.append(target) + figure_targets.add(target) # TODO-NEXT: Add fetching unfiltered data for the Filter.targets as well, once dynamic filters become "targetable" # from other actions too. For example, in future, if Parameter is targeting only a single Filter. diff --git a/vizro-core/src/vizro/actions/_parameter_action.py b/vizro-core/src/vizro/actions/_parameter_action.py index bfc58014f..9ed72783a 100644 --- a/vizro-core/src/vizro/actions/_parameter_action.py +++ b/vizro-core/src/vizro/actions/_parameter_action.py @@ -5,7 +5,7 @@ from dash import ctx from vizro.actions._actions_utils import _get_modified_page_figures -from vizro.managers._model_manager import ModelID +from vizro.managers._model_manager import ModelID, model_manager from vizro.models.types import capture @@ -22,11 +22,26 @@ def _parameter(targets: list[str], **inputs: dict[str, Any]) -> dict[ModelID, An Dict mapping target component ids to modified charts/components e.g. {'my_scatter': Figure({})} """ - target_ids: list[ModelID] = [target.split(".")[0] for target in targets] # type: ignore[misc] + # figure_targets: list[ModelID] = [target.split(".") for target in targets] # type: ignore[misc] + + # need to provide current page or just get all Filters from whole dashboard + figure_targets = targets + filters = [ + filter for filter in cast(Iterable[Filter], model_manager._get_models(Filter, page=page)) if filter._dynamic + ] + + filter_targets = set() + + for figure_target in figure_targets: + figure_target_id, figure_target_argument = figure_target.split(".", 1) + if figure_target_argument.startswith("data_frame"): + for filter in filters: + if figure_target_id in filter.targets: + filter_targets.add(filter.id) return _get_modified_page_figures( ctds_filter=ctx.args_grouping["external"]["filters"], ctds_filter_interaction=ctx.args_grouping["external"]["filter_interaction"], ctds_parameter=ctx.args_grouping["external"]["parameters"], - targets=target_ids, + targets=figure_targets + list(filter_targets), )