-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusage.py
More file actions
58 lines (48 loc) · 1.53 KB
/
usage.py
File metadata and controls
58 lines (48 loc) · 1.53 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import random
import time
import plotly.express as px
from dash import Input, Dash, Output, callback, ctx, dcc, html, no_update, ALL, MATCH
from dash_intersection_observer import DashIntersectionObserver
app = Dash(__name__)
app.layout = html.Div(
[html.Button("Reset", id="reset")]
+ [
html.Div(
[
html.H3(f"Graph {i + 1}"),
dcc.Loading(
DashIntersectionObserver(
html.Div(style={"background": "lightgray", "height": "100%"}),
id={"type": "observer", "index": i},
triggerOnce=True,
style={"height": 450},
threshold=0.25,
),
),
]
)
for i in range(5)
],
style={"display": "grid", "gap": "1rem", "margin": "0 auto", "maxWidth": 800}
)
@callback(
Output({"type": "observer", "index": MATCH}, "children"),
Input({"type": "observer", "index": MATCH}, "inView"),
)
def update_child(in_view):
if not in_view:
return no_update
time.sleep(1)
figure = px.line(y=[random.random() for _ in range(10)]).update_layout(
margin={"l": 0, "b": 0, "t": 0, "r": 0},
)
return dcc.Graph(figure=figure)
@callback(
Output({"type": "observer", "index": ALL}, "inViewCount"),
Input("reset", "n_clicks"),
prevent_initial_call=True,
)
def reset_in_view(_):
return [0] * len(ctx.outputs_list)
if __name__ == '__main__':
app.run_server(debug=True)