Is it possible to save to CSV Dash DataTable after user’s manual modification (for example changing text in the cells)?
Script below add new row to Dash DataTable. For test purpose please change manually as well cell value…
1) Can save Dash DataTable output after adding line and manual modification to CSV file? I have already created "Save new row" button, which is intended to save file to CSV file.
- Is there any possibility in dash to create message to user, for example if user clicks more than one time to the “add new row” button?
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
app = dash.Dash()
app.scripts.config.serve_locally = True
app.css.config.serve_locally = True
INITIAL_ROWS = [
{‘a’: ‘Miami’, ‘b’: “FL”},
{‘a’: ‘Redwood City’, ‘b’: “CA”},
{‘a’: ‘Chicago’, ‘b’: “IL”}
]
EXTRA_ROWS = [
{‘a’: ‘Naperville’, ‘b’: “IL”}]
app.layout = html.Div([
dt.DataTable(rows=INITIAL_ROWS, row_selectable=False,
filterable=True, sortable=True,
selected_row_indices=[], id=‘my_cities_datatable’),
html.Button(“Add new row”, id=‘get_new_row_button_id’),
html.Button(“Save new row”, id=‘save_new_row_button_id’),
], className=“container”)
@app.callback(
Output(‘my_cities_datatable’, ‘rows’),
[Input(‘get_new_row_button_id’, ‘n_clicks’),
Input(‘get_new_row_button_id’, ‘id’)])
def get_new_row(n_clicks, id_name):
print
“n_clicks=%s, id_name=%s” % (n_clicks, id_name)
if n_clicks == None:
return INITIAL_ROWS
if n_clicks ==1:
return INITIAL_ROWS + EXTRA_ROWS
if n_clicks > 1:
return print(“save current row before adding another row”)
app.css.append_css({
“external_url”: “https://codepen.io/chriddyp/pen/bWLwgP.css”
})
if name == ‘main’:
app.run_server(debug=True)