Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Dataframe parameter updates dynamic filter automatically #922

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions vizro-core/src/vizro/actions/_actions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 18 additions & 3 deletions vizro-core/src/vizro/actions/_parameter_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably move this code into Parameter.set_actions.


# 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),
)
Loading