Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
471f99b
Remove actions chain from all models except Page
antonymilne Jul 24, 2025
8ece821
Remove actions loop itself. Still need to handle page load, filter_in…
antonymilne Jul 24, 2025
88e21be
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2025
28baeca
Fixed on_page_load but not yet filter_interaction or gateway
antonymilne Jul 24, 2025
2f97063
Implement gateway but not yet filter_interaction
antonymilne Jul 28, 2025
bb46485
Tidy
antonymilne Jul 28, 2025
8f10d80
Roll out changes across all components and implement filter_interaction
antonymilne Jul 28, 2025
292f111
Tidy and update some tests
antonymilne Jul 28, 2025
5e38a64
Lint
antonymilne Jul 28, 2025
071fc13
Merge remote-tracking branch 'origin/main' into tidy/remove-actions-loop
antonymilne Jul 29, 2025
619049d
Update docs
antonymilne Jul 29, 2025
91dcaf3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2025
b1c420a
Fix scratch_dev app
antonymilne Jul 29, 2025
9109cdc
Fix integration tests
antonymilne Jul 29, 2025
9172bbc
PR review Max
maxschulz-COL Aug 6, 2025
d1c7505
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2025
282ad21
Fix two bugs with url params
petar-qb Aug 8, 2025
a1c5c9f
Merge branch 'tidy/remove-actions-loop' of https://github.com/mckinse…
petar-qb Aug 8, 2025
1ac440f
Merge branch 'main' of https://github.com/mckinsey/vizro into tidy/re…
petar-qb Aug 8, 2025
1952782
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2025
298be15
Move guard_actions_chain to client side
petar-qb Aug 11, 2025
0edbd26
Minor
petar-qb Aug 11, 2025
510eca9
Merge branch 'main' of https://github.com/mckinsey/vizro into tidy/re…
petar-qb Aug 11, 2025
c5f5463
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2025
0f0e4c9
Change model validators to follow conventional format
antonymilne Aug 12, 2025
be73e2d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 12, 2025
a3e0263
Fix the bug when DFP triggers N-1 filter actions on the page
petar-qb Aug 13, 2025
10e814f
Merge branch 'tidy/remove-actions-loop' of https://github.com/mckinse…
petar-qb Aug 13, 2025
3225cbf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2025
e8443e6
Move creation of action components to the action._dash_components
petar-qb Aug 13, 2025
3e53d3a
Moving guard component creation from form to controls models
petar-qb Aug 13, 2025
49d2455
More examples
petar-qb Aug 14, 2025
645f5dc
Merge branch 'main' of https://github.com/mckinsey/vizro into tidy/re…
petar-qb Aug 14, 2025
0a2e343
Lint
petar-qb Aug 14, 2025
1b4cc6e
Lint
petar-qb Aug 14, 2025
ca225c1
More tests
petar-qb Aug 14, 2025
895c72c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 14, 2025
eac0b4d
Test vizro_url and vizro_download components
petar-qb Aug 14, 2025
05c13c5
Addressing PR comments
petar-qb Aug 14, 2025
5fbd1c4
Merge branch 'main' of https://github.com/mckinsey/vizro into tidy/re…
petar-qb Aug 14, 2025
9f0a3e2
Minor
petar-qb Aug 15, 2025
95ca082
Wrap the control's build/call selector_obj in an html.Div to successf…
petar-qb Aug 15, 2025
5dff07e
Addressing the rest of the PR comments any removing scratch_max example
petar-qb Aug 15, 2025
13114ee
[Tidy] Enable users to pass a single action to the `actions` argument…
huong-li-nguyen Aug 15, 2025
1268d67
Revert changes in schema 0.1.44
petar-qb Aug 15, 2025
419f95b
Fix failing unit tests
petar-qb Aug 18, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Removed

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Added

- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Removed

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->

### Added

- Enable passing a single action to the `actions` argument e.g. `actions=export_data()`. ([#1328](https://github.com/mckinsey/vizro/pull/1328))


<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Removed

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
### Added

- Enable single string outputs in `Action` model. You can now specify `outputs="component_id.property"` instead of `outputs=["component_id.property"]` for a single output. ([#1334](https://github.com/mckinsey/vizro/pull/1334))
<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
62 changes: 29 additions & 33 deletions vizro-core/docs/pages/user-guides/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,8 @@ class Jumbotron(vm.VizroBaseModel):

2. Build the component using existing `dash` components.
```py
return html.Div(
...
)
...
)
def build(self):
return html.Div(...)
```
3. Since the new model will be inserted into the `components` argument of the [`Page`][vizro.models.Page], it will be part of the discriminated union describing the allowed types for that argument, in this case the [`ComponentType`][vizro.models.types.ComponentType]. Hence we must:
- define a new type:
Expand Down Expand Up @@ -390,16 +387,17 @@ Add the custom action `open_offcanvas` as a `function` argument inside the [`Act

As mentioned above, custom components can trigger actions. To enable the custom component to trigger the action, add the `actions` field and specify which property triggers the actions:

1. **Add the `actions` argument to your custom component**. The type of the `actions` argument is `list[ActionType]`.
2. **Set the action through `_action_validator_factory`**. In doing so, any change in the `"active_index"` property of the custom component triggers the action.
1. **Add the `actions` argument to your custom component**. The type of the `actions` argument is [`ActionsType`][vizro.models.types.ActionsType].
2. **Set the action trigger through `make_actions_chain` and `_action_triggers`**. In the below example, any change in the `active_index` property of the custom component triggers the actions chain.

```py
actions: Annotated[
list[ActionType],
AfterValidator(_action_validator_factory("active_index")),
PlainSerializer(lambda x: x[0].actions),
Field(default=[]),
]
actions: ActionsType = []

_make_actions_chain = model_validator(mode="after")(make_actions_chain)

@property
def _action_triggers(self):
return {"__default__": f"{self.id}.active_index"}
```


Expand All @@ -411,32 +409,31 @@ As mentioned above, custom components can trigger actions. To enable the custom

import dash_bootstrap_components as dbc
import vizro.models as vm
from pydantic import AfterValidator, Field, PlainSerializer
from pydantic import model_validator
from vizro import Vizro
from vizro.models.types import ActionType
from vizro.models._action._actions_chain import _action_validator_factory
from vizro.models.types import capture
from vizro.models._models_utils import make_actions_chain
from vizro.models.types import ActionsType, capture


class Carousel(vm.VizroBaseModel): # (1)!
type: Literal["carousel"] = "carousel"
items: list
actions: Annotated[
list[ActionType],
AfterValidator(_action_validator_factory("active_index")), # (2)!
PlainSerializer(lambda x: x[0].actions), # (3)!
Field(default=[]),
]
actions: ActionsType = []

_make_actions_chain = model_validator(mode="after")(make_actions_chain)

@property
def _action_triggers(self):
return {"__default__": f"{self.id}.active_index"} # (2)!

def build(self):
return dbc.Carousel(
id=self.id,
items=self.items,
)
return dbc.Carousel(id=self.id, items=self.items)

vm.Page.add_type("components", Carousel) # (4)!

@capture("action") # (5)!
vm.Page.add_type("components", Carousel) # (3)!


@capture("action") # (4)!
def slide_next_card(active_index):
if active_index:
return "Second slide"
Expand All @@ -447,14 +444,14 @@ As mentioned above, custom components can trigger actions. To enable the custom
title="Custom Component",
components=[
vm.Card(text="First slide", id="carousel-card"),
Carousel( # (6)!
Carousel( # (5)!
id="carousel",
items=[
{"key": "1", "src": "assets/slide_1.jpg"},
{"key": "2", "src": "assets/slide_2.jpg"},
],
actions=[
vm.Action( # (7)!
vm.Action( # (6)!
function=slide_next_card(),
inputs=["carousel.active_index"],
outputs=["carousel-card.children"],
Expand All @@ -469,8 +466,7 @@ As mentioned above, custom components can trigger actions. To enable the custom
```

1. Here we subclass `VizroBaseModel` to create a new `Carousel` component.
1. We set the action so a change in the `active_index` property of the custom component triggers the action. `_action_validator_factory("active_index")` ensures that an `Action` model is correctly created and validated.
1. We tell the serializer to only serialize the `actions` field. This is important for when the dashboard configuration is exported (e.g., to YAML or JSON).
1. We set `_action_triggers` so that a change in the `active_index` property of the `dbc.Carousel` component triggers the action.
1. **Remember!** If part of a discriminated union, you must add the new component to the parent model where it will be inserted. In this case the new `Carousel` will be inserted into the `components` argument of the `Page` model, and thus must be added as an allowed type.
1. We define a custom action `slide_next_card` using the `@capture("action")` decorator. This action will change the text of a `Card` component based on the active slide in the `Carousel`.
1. We add the `Carousel` component to the page, providing items for the carousel.
Expand Down
Loading
Loading