Skip to content
This repository was archived by the owner on Jun 22, 2019. It is now read-only.

Commit 7019bcc

Browse files
committed
add editable example
1 parent d934c6a commit 7019bcc

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ For updates and more, please see the [dash community discussion on tables](https
1414
$ pip install dash-table-experiments
1515
```
1616

17-
See [usage.py](https://github.com/plotly/dash-table-experiments/tree/master/usage.py)
17+
See [usage.py](https://github.com/plotly/dash-table-experiments/tree/master/usage.py) and
18+
See [usage-editable.py](https://github.com/plotly/dash-table-experiments/tree/master/usage-editable.py)

images/Editable-DataTable.gif

-99.7 KB
Loading

usage-editable.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import dash
2+
from dash.dependencies import Input, Output, State
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import dash_table_experiments as dt
6+
import json
7+
import pandas as pd
8+
import plotly
9+
10+
app = dash.Dash()
11+
12+
app.scripts.config.serve_locally = True
13+
14+
15+
DF_SIMPLE = pd.DataFrame({
16+
'x': ['A', 'B', 'C', 'D', 'E', 'F'],
17+
'y': [4, 3, 1, 2, 3, 6],
18+
'z': ['a', 'b', 'c', 'a', 'b', 'c']
19+
})
20+
21+
22+
app.layout = html.Div([
23+
html.H4('Editable DataTable'),
24+
dt.DataTable(
25+
rows=DF_SIMPLE.to_dict('records'),
26+
27+
# optional - sets the order of columns
28+
columns=sorted(DF_SIMPLE.columns),
29+
30+
editable=True,
31+
32+
id='editable-table'
33+
),
34+
html.Div([
35+
html.Pre(id='output', className="two columns"),
36+
html.Div(
37+
dcc.Graph(
38+
id='graph',
39+
style={
40+
'overflow-x': 'wordwrap'
41+
}
42+
),
43+
className="ten columns"
44+
)
45+
], className="row")
46+
], className="container")
47+
48+
49+
@app.callback(
50+
Output('output', 'children'),
51+
[Input('editable-table', 'rows')])
52+
def update_selected_row_indices(rows):
53+
return json.dumps(rows, indent=2)
54+
55+
56+
@app.callback(
57+
Output('graph', 'figure'),
58+
[Input('editable-table', 'rows')])
59+
def update_figure(rows):
60+
dff = pd.DataFrame(rows)
61+
return {
62+
'data': [{
63+
'x': dff['x'],
64+
'y': dff['y'],
65+
}],
66+
'layout': {
67+
'margin': {'l': 10, 'r': 0, 't': 10, 'b': 20}
68+
}
69+
}
70+
71+
72+
app.css.append_css({
73+
"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"
74+
})
75+
76+
if __name__ == '__main__':
77+
app.run_server(debug=True)

0 commit comments

Comments
 (0)