30. Dash Table

Out:

"\napp = dash.Dash(__name__)\n\napp.layout = html.Div([\n    html.Div([\n        dcc.Input(\n            id='adding-rows-name',\n            placeholder='Enter a column name...',\n            value='',\n            style={'padding': 10}\n        ),\n        html.Button('Add Column', id='adding-rows-button', n_clicks=0)\n    ], style={'height': 50}),\n\n    dash_table.DataTable(\n        id='adding-rows-table',\n        columns=[{\n            'name': 'Column {}'.format(i),\n            'id': 'column-{}'.format(i),\n            'deletable': True,\n            'renamable': True\n        } for i in range(1, 5)],\n        data=[\n            {'column-{}'.format(i): (j + (i-1)*5) for i in range(1, 5)}\n            for j in range(5)\n        ],\n        editable=True,\n        row_deletable=True\n    ),\n\n    html.Button('Add Row', id='editing-rows-button', n_clicks=0),\n\n    dcc.Graph(id='adding-rows-graph')\n])\n\n\n@app.callback(\n    Output('adding-rows-table', 'data'),\n    Input('editing-rows-button', 'n_clicks'),\n    State('adding-rows-table', 'data'),\n    State('adding-rows-table', 'columns'))\ndef add_row(n_clicks, rows, columns):\n    if n_clicks > 0:\n        rows.append({c['id']: '' for c in columns})\n    return rows\n\n\n@app.callback(\n    Output('adding-rows-table', 'columns'),\n    Input('adding-rows-button', 'n_clicks'),\n    State('adding-rows-name', 'value'),\n    State('adding-rows-table', 'columns'))\ndef update_columns(n_clicks, value, existing_columns):\n    if n_clicks > 0:\n        existing_columns.append({\n            'id': value, 'name': value,\n            'renamable': True, 'deletable': True\n        })\n    return existing_columns\n\n\n@app.callback(\n    Output('adding-rows-graph', 'figure'),\n    Input('adding-rows-table', 'data'),\n    Input('adding-rows-table', 'columns'))\ndef display_output(rows, columns):\n    return {\n        'data': [{\n            'type': 'heatmap',\n            'z': [[row.get(c['id'], None) for c in columns] for row in rows],\n            'x': [c['name'] for c in columns]\n        }]\n    }\n\n\nif __name__ == '__main__':\n    app.run_server(debug=True)\n"

 9 import dash
10 from dash.dependencies import Input, Output, State
11 import dash_table
12 import dash_core_components as dcc
13 import dash_html_components as html
14
15 """
16 app = dash.Dash(__name__)
17
18 app.layout = html.Div([
19     html.Div([
20         dcc.Input(
21             id='adding-rows-name',
22             placeholder='Enter a column name...',
23             value='',
24             style={'padding': 10}
25         ),
26         html.Button('Add Column', id='adding-rows-button', n_clicks=0)
27     ], style={'height': 50}),
28
29     dash_table.DataTable(
30         id='adding-rows-table',
31         columns=[{
32             'name': 'Column {}'.format(i),
33             'id': 'column-{}'.format(i),
34             'deletable': True,
35             'renamable': True
36         } for i in range(1, 5)],
37         data=[
38             {'column-{}'.format(i): (j + (i-1)*5) for i in range(1, 5)}
39             for j in range(5)
40         ],
41         editable=True,
42         row_deletable=True
43     ),
44
45     html.Button('Add Row', id='editing-rows-button', n_clicks=0),
46
47     dcc.Graph(id='adding-rows-graph')
48 ])
49
50
51 @app.callback(
52     Output('adding-rows-table', 'data'),
53     Input('editing-rows-button', 'n_clicks'),
54     State('adding-rows-table', 'data'),
55     State('adding-rows-table', 'columns'))
56 def add_row(n_clicks, rows, columns):
57     if n_clicks > 0:
58         rows.append({c['id']: '' for c in columns})
59     return rows
60
61
62 @app.callback(
63     Output('adding-rows-table', 'columns'),
64     Input('adding-rows-button', 'n_clicks'),
65     State('adding-rows-name', 'value'),
66     State('adding-rows-table', 'columns'))
67 def update_columns(n_clicks, value, existing_columns):
68     if n_clicks > 0:
69         existing_columns.append({
70             'id': value, 'name': value,
71             'renamable': True, 'deletable': True
72         })
73     return existing_columns
74
75
76 @app.callback(
77     Output('adding-rows-graph', 'figure'),
78     Input('adding-rows-table', 'data'),
79     Input('adding-rows-table', 'columns'))
80 def display_output(rows, columns):
81     return {
82         'data': [{
83             'type': 'heatmap',
84             'z': [[row.get(c['id'], None) for c in columns] for row in rows],
85             'x': [c['name'] for c in columns]
86         }]
87     }
88
89
90 if __name__ == '__main__':
91     app.run_server(debug=True)
92 """

Total running time of the script: ( 0 minutes 0.100 seconds)

Gallery generated by Sphinx-Gallery