-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash-app.py
85 lines (75 loc) · 2.04 KB
/
dash-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
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
import itertools
import json
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import pandas as pd
from dash.dependencies import Input, Output
import os
import flask
from random import shuffle
import numpy as np
####
from utils import excel_cols
server = flask.Flask(__name__)
server.secret_key = os.environ.get('secret_key', str(np.random.randint(0, 1000000)))
app = dash.Dash(__name__, server=server)
####
n_rows = 10000
list_excel_cols = list(itertools.islice(excel_cols(), n_rows))
list_excel_cols_shuffled = list(itertools.islice(excel_cols(), n_rows))
shuffle(list_excel_cols_shuffled)
df_rows = pd.DataFrame({
'index': np.arange(n_rows),
'x': list_excel_cols,
'y': np.random.randint(0, 100, n_rows),
})
app.layout = html.Div([
html.H4('Editable DataTable'),
html.H6('%d rows' % n_rows),
dt.DataTable(
rows=df_rows.to_dict('records'),
columns=sorted(df_rows.columns),
editable=True,
id='editable-table'
),
html.Div([
#html.Pre(id='output', className='two columns'),
html.Div(
dcc.Graph(
id='graph',
style={
'overflow-x': 'wordwrap'
}
),
className='ten columns'
)], className='row')
], className='container')
'''
@app.callback(
Output('output', 'children'),
[Input('editable-table', 'rows')])
def update_selected_row_indices(rows):
return json.dumps(rows, indent=2)
'''
@app.callback(
Output('graph', 'figure'),
[Input('editable-table', 'rows')])
def update_figure(rows):
dff = pd.DataFrame(rows)
return {
'data': [{
'x': dff['x'],
'y': dff['y'],
'index': dff['index']
}],
'layout': {
'margin': {'l': 10, 'r': 0, 't': 10, 'b': 20}
}
}
app.css.append_css({
'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})
if __name__ == '__main__':
app.server.run(debug=True, threaded=True)