mckinsey / vizro

Vizro is a toolkit for creating modular data visualization applications.
https://vizro.readthedocs.io/en/stable/
Apache License 2.0
2.72k stars 142 forks source link

[Feat] Enable dynamic filter #879

Open petar-qb opened 1 week ago

petar-qb commented 1 week ago

Description

This PR introduces dynamic filters for the following selectors (so, all Vizro selectors except vm.DatePicker): vm.Dropdown, vm.RadioItems, vm.Checklist, vm.Slider and vm.RangeSlider

You can test the feature by altering values in the scratch_dev/data.yaml (in the way that's described in the comment) and running the scratch_dev/app.py.

TODOs:

This PR TODOs:

This or next PR TODOs (we should decide it):

Next PRs:

References:

Open questions:

  1. How to enable dynamic Parameters? Should we allow, for example, the "options" property of a categorical parameter selector to be a function that dynamically calculates and returns new options?
  2. How to enable a dynamic filter to be targeted by any predefined action? For example the parameter_action target. Or like this: update_figures(targets=[”filter_1_id”])
  3. What exactly is a new way of dash persistence handling we expect (this fix will be implemented by us)?
  4. If we introduce the data_frame property for the vm.Filter component, and if the data_frame Parameters change the targeting form to data_manager_key.function_argument, does is mean that our dynamic Filters could be handled in a same way as any other dynamic figure components?

Notice

github-actions[bot] commented 1 week ago

View the example dashboards of the current commit live on PyCafe :coffee: :rocket:

Updated on: 2024-11-21 12:16:03 UTC Commit: 53d73e56671e944cdc426183a14b5cdfdf0a1d4f

Link: vizro-core/examples/dev/

Link: vizro-core/examples/scratch_dev

Link: vizro-core/examples/visual-vocabulary/

Link: vizro-ai/examples/dashboard_ui/

antonymilne commented 3 days ago

This or next PR TODOs (we should decide it):

  • [ ] - Support dynamic for the vm.DatePicker. (Maybe it's better to wait for the dash persistence bugfix as persistence doesn't work for the vm.DatePicker even on the main branch)

Definitely not urgent. Let's wait for this and fix https://github.com/plotly/dash/issues/2678 first.

Next PRs:

How many of these will still be problems once we fix https://github.com/plotly/dash/issues/2678?

  • [ ] - Enable dynamic filter to work with the empty data_frame.

Good idea - let's discuss how this works now and how it should work.

  • [ ] - Propagate data_frame Parameter default values from the model_manager into the DM._multi_load() that's called from the vm.Filter.pre_build(). -> PoC can be found in the comment.

Added to the comment there but basically let's leave as a TODO and open a ticket. Not urgent.

  • [ ] - Implement "Select ALL" for the multi=True categorical selectors.

Would love to do this soon (like by end of year if possible).

  • [ ] - Implement "Select the entire range" for the multi=True numerical selectors.

Not as high priority - let's make a ticket and forget for now.

Open questions:

  1. How to enable dynamic Parameters? Should we allow, for example, the "options" property of a categorical parameter selector to be a function that dynamically calculates and returns new options?

Good question but I think not super high priority unless we have an immediate use for it.

  1. How to enable a dynamic filter to be targeted by any predefined action? For example the parameter_action target. Or like this: update_figures(targets=[”filter_1_id”])

Very good question and presumably required for us to get DFPs to update filters without reloading the page? So this one needs to be worked out soon.

  1. What exactly is a new way of dash persistence handling we expect (this fix will be implemented by us)?

Let's discuss but I think basically the "common sense" way that we initially expected things to work.

  1. If we introduce the data_frame property for the vm.Filter component, and if the data_frame Parameters change the targeting form to data_manager_key.function_argument, does is mean that our dynamic Filters could be handled in a same way as any other dynamic figure components?

Not sure I understand this, please could you explain?


Basically I think roughly ordered priorities are:

  1. Finish this PR
  2. Fix https://github.com/plotly/dash/issues/2678
  3. Tidy our code, see what remaining cases remain to fix
  4. DFP to update filters without reloading page
  5. @antonymilne completes some current work coming from #363 on class-based action and refactoring
  6. Implement "Select ALL" for the multi=True categorical selectors. https://github.com/McK-Internal/vizro-internal/issues/1342#issue-2618580976

    wdyt?