-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathusage-persistence.py
47 lines (40 loc) · 1.18 KB
/
usage-persistence.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
An example to show how to use persistence. After loading data, refreshing
the page should not loose the cytoscape data nor the selection of nodes/edges.
Persistence should be set to:
- local
- session
- memory
Read more about persistence here: https://dash.plotly.com/persistence
"""
import dash
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
import dash_cytoscape as cyto
import dash_html_components as html
elements = [
{'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}},
{'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}},
{'data': {'source': 'one', 'target': 'two', 'label': 'Node 1 to 2'}}
]
layout = {'name': 'grid'}
app = dash.Dash(__name__)
app.layout = html.Div([
html.Button('Load data', id='bt-load'),
cyto.Cytoscape(
id='cytoscape',
layout=layout,
# persistence=True
),
])
@app.callback(
Output('cytoscape', 'elements'),
[Input('bt-load', 'n_clicks')]
)
def load_elements(_):
ctx = dash.callback_context
if not ctx.triggered:
raise PreventUpdate
return elements
if __name__ == '__main__':
app.run_server(debug=True)