"""Example to show the reset of the filter values on a button click."""
from dash import callback, Input, Output
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.models.types import capture
@callback(
Output("continent_filter", "value", allow_duplicate=True),
Output("country_filter", "value", allow_duplicate=True),
Output("life_exp_filter", "value", allow_duplicate=True),
Input("reset_button", "n_clicks"),
prevent_initial_call=True
)
def reset_filters(n_clicks):
return ["ALL"], ["ALL"], [23, 83]
# TODO: (Remove) This is an example how it would work if the AV2-Stage-1 were implemented
# @capture("action")
# def reset_filters():
# return ["ALL"], ["ALL"], [23, 83]
vm.Page.add_type("controls", vm.Button)
page_one = vm.Page(
title="Graph / AG Grid",
components=[
vm.Graph(
figure=px.scatter(
data_frame=px.data.gapminder(),
x="continent",
y="lifeExp",
color="continent",
title="Graph",
)
)
],
controls=[
vm.Filter(
column="continent",
selector=vm.Dropdown(id="continent_filter")
),
vm.Filter(
column="country",
selector=vm.Dropdown(id="country_filter")
),
vm.Filter(
column="lifeExp",
selector=vm.RangeSlider(id="life_exp_filter", min=23, max=83, step=1, marks=None)
),
vm.Button(
id="reset_button",
text="Reset filters",
# TODO: (Remove) This is an example how it would work if the AV2-Stage-1 were merged
# actions=[
# vm.Action(
# function=reset_filters(),
# outputs=[
# "continent_filter.value",
# "country_filter.value",
# "life_exp_filter.value",
# ]
# )
# ]
)
]
)
dashboard = vm.Dashboard(pages=[page_one])
Vizro().build(dashboard).run(debug=True)