Py.Cafe

lingyielia/

vizro-enhanced-data-visualization

Enhanced Data Visualization with Vizro

DocsPricing
  • app.py
  • dashboard.yaml
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
######################################################################
# Steps to check your YAML configuration from Python dashboard:
# 1. In dashboard.yaml, replace <REPLACE ME> with references to data sources.
# 2. In app.py, make sure data sources are registered in data manager.
# 3. In app.py, define any custom charts/figures/tables/actions.
# 4. Make sure dashboard works as expected.
######################################################################
from pathlib import Path

import vizro.plotly.express as px
import yaml
from vizro import Vizro
from vizro.managers import data_manager
from vizro.models import Dashboard
from vizro.models.types import capture

data_manager["gapminder"] = px.data.gapminder()
data_manager["tips"] = px.data.tips()
data_manager["iris"] = px.data.iris()

@capture("graph")
def scatter_with_line(data_frame, x, y, color=None, size=None, hline=None): # (1)!
    fig = px.scatter(data_frame=data_frame, x=x, y=y, color=color, size=size)
    fig.add_hline(y=hline, line_color="gray")
    return fig

dashboard = yaml.safe_load(Path("dashboard.yaml").read_text(encoding="utf-8"))
dashboard = Dashboard(**dashboard)

Vizro().build(dashboard).run()