Skip to content

Commit

Permalink
[Bug] Fix sending an empty list through parameter (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-qb authored Feb 19, 2025
1 parent ec9f248 commit 3e44988
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
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

- Fix a bug where an empty parameter selection incorrectly sent `[None]` to its target. ([#1026](https://github.com/mckinsey/vizro/pull/1026))

<!--
### 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))
-->
91 changes: 30 additions & 61 deletions vizro-core/examples/scratch_dev/app.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,43 @@
"""Test app"""
"""Dev app to try things out."""

from os import chown

import pandas as pd
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
from vizro.models.types import capture

iris = px.data.iris()

page = vm.Page(
title="New Line Height",
layout=vm.Layout(grid=[[0, 1]]),
components=[
vm.Card(
id="new-line-height",
text="""
# New
## What is Vizro?

Vizro is an open-source dashboarding framework developed by McKinsey. Built with Plotly and Dash, Vizro
provides a high-level API for creating interactive, production-ready dashboards with minimal code.
It includes pre-configured layouts, themes, and components, making it easier to build data-driven
applications.
df = px.data.iris()

Even if you're not creating a Vizro app, you can still use its styling and design system in your Dash
applications.

## Vizro Features Available for Dash Apps
* Vizro Bootstrap-themed figure templates are available in the dash-bootstrap-templates library starting
from version 2.1.0. Both dark and light-themed templates are included.
* Vizro Bootstrap theme provides styling for Bootstrap components, allowing them to match the Vizro light
or dark theme.
* Vizro theme for other Dash components extends styling beyond Bootstrap. Vizro includes custom CSS to
theme additional Dash components that are not part of Bootstrap. You can explore all the custom CSS files
in their GitHub repository.
* Vizro KPI cards like the ones shown in the image above can be added to a regular Dash app, bringing a
visually consistent way to display key performance indicators. For more details, see this Plotly forum post.""",
),
vm.Card(
id="old-line-height",
text="""
# Old
@capture("ag_grid")
def my_custom_ag_grid(data_frame, chosen_columns, **kwargs):
print(f"\nChosen column: {chosen_columns}\n")
return dash_ag_grid(data_frame=data_frame[chosen_columns], **kwargs)()

## What is Vizro?

Vizro is an open-source dashboarding framework developed by McKinsey. Built with Plotly and Dash, Vizro
provides a high-level API for creating interactive, production-ready dashboards with minimal code.
It includes pre-configured layouts, themes, and components, making it easier to build data-driven
applications.
Even if you're not creating a Vizro app, you can still use its styling and design system in your Dash
applications.
## Vizro Features Available for Dash Apps
* Vizro Bootstrap-themed figure templates are available in the dash-bootstrap-templates library starting
from version 2.1.0. Both dark and light-themed templates are included.
* Vizro Bootstrap theme provides styling for Bootstrap components, allowing them to match the Vizro light
or dark theme.
* Vizro theme for other Dash components extends styling beyond Bootstrap. Vizro includes custom CSS to
theme additional Dash components that are not part of Bootstrap. You can explore all the custom CSS files
in their GitHub repository.
* Vizro KPI cards like the ones shown in the image above can be added to a regular Dash app, bringing a
visually consistent way to display key performance indicators. For more details, see this Plotly forum post.""",
page = vm.Page(
title="Fix empty dropdown as parameter",
components=[
vm.AgGrid(
id="my_custom_ag_grid",
figure=my_custom_ag_grid(
data_frame=df,
chosen_columns=df.columns.to_list(),
),
)
],
controls=[
vm.Parameter(
targets=["my_custom_ag_grid.chosen_columns"],
selector=vm.Dropdown(
title="Choose columns",
options=df.columns.to_list(),
multi=True,
),
),
],
)
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/actions/_actions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _apply_filter_interaction(
def _validate_selector_value_none(value: Union[SingleValueType, MultiValueType]) -> ValidatedNoneValueType:
if value == NONE_OPTION:
return None
elif isinstance(value, list):
if isinstance(value, list) and len(value):
return [i for i in value if i != NONE_OPTION] or [None] # type: ignore[list-item]
return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def test_one_parameter_one_target(self, ctx_parameter_y, target_scatter_paramete
@pytest.mark.parametrize(
"ctx_parameter_hover_data, target_scatter_parameter_hover_data",
[
([], []),
(["NONE"], [None]),
(["NONE", "pop"], ["pop"]),
(["NONE", "NONE"], [None]),
Expand Down

0 comments on commit 3e44988

Please sign in to comment.