|
1 |
| -"""Test app""" |
| 1 | +import time |
| 2 | + |
| 3 | +import pandas as pd |
2 | 4 |
|
3 | 5 | import vizro.models as vm
|
4 | 6 | import vizro.plotly.express as px
|
5 | 7 | from vizro import Vizro
|
| 8 | +from vizro.managers import data_manager |
6 | 9 |
|
7 |
| -iris = px.data.iris() |
8 | 10 |
|
9 |
| -page = vm.Page( |
10 |
| - title="Page with subsections", |
11 |
| - layout=vm.Layout(grid=[[0, 0, 1, 1, 2, 2], [3, 3, 3, 4, 4, 4], [3, 3, 3, 4, 4, 4]]), |
12 |
| - components=[ |
13 |
| - vm.Card(text="""Hello, this is a card with a [link](https://www.google.com)"""), |
14 |
| - vm.Card(text="""Hello, this is a card with a [link](https://www.google.com)"""), |
15 |
| - vm.Card(text="""Hello, this is a card with a [link](https://www.google.com)"""), |
16 |
| - vm.Container( |
17 |
| - title="Container I", |
18 |
| - components=[ |
19 |
| - vm.Graph(figure=px.scatter(iris, x="sepal_width", y="sepal_length", color="species")), |
20 |
| - ], |
21 |
| - variant="outlined", |
22 |
| - ), |
23 |
| - vm.Container( |
24 |
| - title="Container II", |
25 |
| - components=[ |
26 |
| - vm.Graph(figure=px.scatter(iris, x="sepal_width", y="sepal_length", color="species")), |
27 |
| - ], |
28 |
| - variant="filled", |
29 |
| - ), |
30 |
| - ], |
31 |
| -) |
| 11 | +static_df = pd.DataFrame({ |
| 12 | + "species": ["artificial_species", "artificial_species", "artificial_species"], |
| 13 | + "sepal_width": [4, 5, 6], |
| 14 | + "sepal_length": [4, 5, 6], |
| 15 | +}) |
32 | 16 |
|
33 |
| -page_two = vm.Page( |
34 |
| - title="Container", |
35 |
| - components=[ |
36 |
| - vm.Container( |
37 |
| - title="Container III", |
38 |
| - components=[ |
39 |
| - vm.Graph(figure=px.scatter(iris, x="sepal_width", y="sepal_length", color="species")), |
40 |
| - ], |
41 |
| - ), |
42 |
| - ], |
43 |
| -) |
44 | 17 |
|
45 |
| -page_three = vm.Page( |
46 |
| - title="Container Style", |
| 18 | +def load_data(number_of_points=150): |
| 19 | + # Artificial delay to simulate data loading in production |
| 20 | + print("\nLoading data...\n") |
| 21 | + time.sleep(1) |
| 22 | + |
| 23 | + return px.data.iris().head(number_of_points) |
| 24 | + |
| 25 | + |
| 26 | +data_manager["dynamic_df"] = load_data |
| 27 | + |
| 28 | +page_1 = vm.Page( |
| 29 | + title="Update dynamic filter from DFP", |
47 | 30 | components=[
|
48 |
| - vm.Container( |
49 |
| - title="Container I", |
50 |
| - components=[ |
51 |
| - vm.Graph(figure=px.scatter(iris, x="sepal_width", y="sepal_length", color="species")), |
52 |
| - ], |
53 |
| - variant="outlined", |
54 |
| - ), |
55 |
| - vm.Container( |
56 |
| - title="Container II", |
57 |
| - components=[ |
58 |
| - vm.Graph(figure=px.scatter(iris, x="sepal_width", y="sepal_length", color="species")), |
59 |
| - ], |
60 |
| - variant="filled", |
| 31 | + vm.Graph( |
| 32 | + id="dynamic_graph_1", |
| 33 | + figure=px.scatter(data_frame="dynamic_df", x="sepal_width", y="sepal_length", color="species"), |
61 | 34 | ),
|
| 35 | + vm.Graph( |
| 36 | + figure=px.scatter(data_frame=static_df, x="sepal_width", y="sepal_length", color="species"), |
| 37 | + ) |
62 | 38 | ],
|
| 39 | + controls=[ |
| 40 | + vm.Filter(column="species", selector=vm.RadioItems()), |
| 41 | + vm.Parameter( |
| 42 | + targets=["dynamic_graph_1.data_frame.number_of_points"], |
| 43 | + selector=vm.Slider( |
| 44 | + min=0, |
| 45 | + max=150, |
| 46 | + value=150, |
| 47 | + title="Number of points", |
| 48 | + step=10, |
| 49 | + ) |
| 50 | + ), |
| 51 | + ] |
63 | 52 | )
|
64 |
| -dashboard = vm.Dashboard(pages=[page, page_two, page_three]) |
| 53 | + |
| 54 | +dashboard = vm.Dashboard(pages=[page_1]) |
| 55 | + |
65 | 56 |
|
66 | 57 | if __name__ == "__main__":
|
67 | 58 | Vizro().build(dashboard).run()
|
0 commit comments