-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.py
90 lines (79 loc) · 3.19 KB
/
usage.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import dash_grid_layout as dgl
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.exceptions import PreventUpdate
app = dash.Dash('')
app.scripts.config.serve_locally = True
def generate_new_dash_item(idx, x=0, y=0, w=4, h=4, grid_width=150, grid_height=150):
return html.Div(key=idx,
children=[html.Div(className="widget-drag-handle", children="{} another draggable bit".format(idx)),
# dcc.Graph(
# id='{}-example-graph'.format(idx),
# style={'height': '{}px'.format(h * grid_height), 'width': '{}px'.format(w * grid_width)},
# figure={
# 'data': [
# {'x': [1, 2, 3], 'y': [4, 4, 4], 'type': 'bar', 'name': idx},
# {'x': [1, 2, 3], 'y': [1, 1, 1], 'type': 'bar', 'name': u'Montr?al'},
# ],
# 'layout': {
# 'title': 'Added Data Visualization'
# }
# }
# )
]
)
grid_layout = [
{"i": 'b', "x": 1, "y": 0, "w": 4, "h": 4, "minW": 2, "maxW": 6},
{"i": 'c', "x": 4, "y": 4, "w": 4, "h": 4},
]
app.layout = html.Div(children=[html.Div(id='dash-grid-container',
children=[
dgl.Grid(
id='dash-grid',
layout=grid_layout,
autoSize=True,
cols=8,
rows=8,
rowHeight=155,
width=1280,
draggableHandle="",
children=[
generate_new_dash_item('b'),
generate_new_dash_item('c')
]
),
html.Div(id='output'),
] ), html.Button('add another graph', id='button')
])
# Callback for adding new elements to the grid
# Because the layout is fundamental to the grid, we can't just render the children of the grid,
# we have to render the entire grid
@app.callback(
dash.dependencies.Output('dash-grid-container', 'children'),
[dash.dependencies.Input('button', 'n_clicks')],
[dash.dependencies.State('dash-grid', 'layout'),
dash.dependencies.State('dash-grid', 'children')
])
def display_output(value, layout, children):
if value is None:
raise PreventUpdate()
idx = 'e{}'.format(value)
e_is_in_layout = bool([lyt for lyt in layout if lyt['i'] == idx])
if not e_is_in_layout:
layout.append({"i": idx, "x": 4, "y": 4, "w": 4, "h": 4})
children.append(generate_new_dash_item(idx))
resp = [dgl.Grid(
id='dash-grid',
layout=layout,
autoSize=True,
cols=8,
rows=8,
rowHeight=155,
width=1280,
draggableHandle=".widget-drag-handle",
children=children
)]
return resp
if __name__ == '__main__':
app.run_server(debug=True)