import vizro.plotly.express as px
from vizro import Vizro
import vizro.models as vm
from vizro.managers import model_manager
### WARNING: These are temporarily to work around some pycafe and/or vizro issues
### and will not be needed in the future
# NOTE: also choose the pyodide-v0.26.x runtime in settings
import dash._pages
dash._pages.context_value.set({})
Vizro._reset()
# From Maximilian Schulz:
# Hack to stop app crashing when query parameters are specified: allow the layout function to accept **kwargs.
# Something like this will probably be built into vizro in the future so you wouldn't need to do this.
class DashboardWithQueryParameter(vm.Dashboard):
def _make_page_layout(self, page: vm.Page, **kwargs):
return super()._make_page_layout(page)
### WARNING: the code above is temporarily
### Here is where the normal vizro code goes:
df = px.data.iris()
page = vm.Page(
title="My first dashboard",
components=[
vm.Graph(id="scatter_chart", figure=px.scatter(df, x="sepal_length", y="petal_width", color="species")),
vm.Graph(id="hist_chart", figure=px.histogram(df, x="sepal_width", color="species")),
],
controls=[
vm.Filter(column="species", selector=vm.Dropdown(value=["ALL"])),
],
)
dashboard = DashboardWithQueryParameter(pages=[page])
vizro = Vizro()
app = vizro.build(dashboard).dash