✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Dash table edited data not persisting

I am trying to persist the data in a data table. One of the columns (Channel3) is editable. I have specified persistence=True and persistence_type=‘local’.

When I edit the value in a cell in Channel3 column, then press F5 (to refresh the page), the new value persists only 1 time. If I press F5 again, the new value disappears (the old value appears). So it seems that upon page refresh, the new value is persisted only 1 time. The expected behavior is that the new value should persist across page refreshes as per Persistence documentation for ‘local’.

Is it a bug or I am doing something wrong ?

Does the callback have something to do with it ?

This is my test example for later adding code to persist the edited data across tabs. First I have to get this one to work.

This is the code:

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash.dependencies as ddep
import dash_table as dt
import dash_table.Format as dtfmt

import pandas as pd
import datetime
import random


import dash

app = dash.Dash(__name__,  show_undo_redo=False, url_base_pathname='/'
                ) 
app.config.suppress_callback_exceptions = True




l = [['24-01-2020', 2,3,4], ['25-01-2020', 6,7,8], ['25-01-2020', 17,14,22]]
df = pd.DataFrame(columns=['order_dt', 'channel1', 'channel2', 'channel3'], data=l)

table_columns = [
                    {'name':'Date', 'id':'order_dt', 'editable':False, 'type':'datetime'},
                    {'name':'Channel1', 'id':'channel1', 'editable':False, 'type':'numeric'},
                    {'name':'Channel2', 'id':'channel2', 'editable':False, 'type':'numeric'},
                    {'name':'Channel3', 'id':'channel3', 'editable':True, 'type':'numeric'}
                ]
ord_datatable = dt.DataTable(
                            id='ord',
                            columns = table_columns,
                            data = df.to_dict('rows'),
                            persistence=True,
                            persisted_props = [
                                                'columns.name',
                                                'data',
                                                'filter_query',
                                                'hidden_columns',
                                                'selected_columns',
                                                'selected_rows',
                                                'sort_by'
                                              ],
                            persistence_type = 'local'
                        )



app.layout = html.Div(children=
                                          [
                                              ord_datatable,
                                              html.Button(className='button', id='refresh_button', n_clicks=0, children=['Refresh'])
                                           ])


@app.callback(
                ddep.Output(component_id='ord', component_property='data'),
               [ddep.Input(component_id='refresh_button', component_property='n_clicks')],
                [ddep.State(component_id='ord', component_property='data')] 
             )
def update_data(n_clicks, rows):
    if n_clicks > 0:
        for row in rows:
            print('row={}'.format(row))
        return (rows)
    else:
        return (rows)




if __name__ == '__main__':
    app.run_server()           

@tcbegley thank you very much for responding. I have now raised an issue: