DataTable "data_previous" and "data_timestamp" not set if the DataTable data modified by a callback

Hi,

I came across that ‘data_previous’ and ‘data_timestamp’ values of a DataTable are not assigned unless the user edits DataTable explicitly. If the DataTable is edited by a callback, it’s ‘data_previous’ and 'data_timestamp ’ remain the same. I understood from the documentation that these properties should change if the data is modified by a callback.

My original table is created inside a callback. I have also tried to set data_previous explicitly when the table is created, but it didn’t help either.

I’m using a bit obsolete setup though, is this changed in the recent versions?

dash==0.43.0
dash-bootstrap-components==0.7.0
dash-core-components==0.48.0
dash-daq==0.1.0
dash-html-components==0.16.0
dash-renderer==0.24.0
dash-table==3.7.0

This is still an active problem.

I append an extra row with a callback and the data_previous will not be set correctly.

I use a recent version of dash (dash 1.4.0 and dash-table 4.4.0) and also tried it with the latest.

Here is a minimal example showing the problem:

import json

import dash
import dash_html_components as html
import dash_table as dt
from dash.dependencies import Input, Output, State

app = dash.Dash(__name__)

table_data = [
    {'A': 1, 'B': 2, 'C': 3},
    {'A': 3, 'B': 4, 'C': 5},
]
columns = [{'id': 'A', 'name': 'A'},
           {'id': 'B', 'name': 'C'},
           {'id': 'C', 'name': 'C'}]

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    html.Button('Add Row', id='adding_rows_button', n_clicks=0),

    dt.DataTable(
        id='test_table',
        columns=columns,
        data=table_data,
        editable=True,
        row_deletable=True,
    ),

    html.Div(id='out_div'),
    html.P(),
    html.Div(id='out_div_prev')
])


@app.callback(
    Output('test_table', 'data'),
    [Input('adding_rows_button', 'n_clicks')],
    [State('test_table', 'data')])
def add_row(n_clicks, rows):
    if n_clicks:
        rows.append({'A': 3, 'B': 4, 'C': 5})
    return rows


@app.callback(
    [Output("out_div", "children"),
     Output("out_div_prev", "children")],
    [Input("test_table", "data")],
    [State("test_table", "data_previous")])
def show_prev(data, data_prev):
    return json.dumps(data), json.dumps(data_prev)


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

Is there any chance, someone could take a look at this problem?

The value data_previous is definitly not working as documented.
I also created an issue in the DataTable Github: https://github.com/plotly/dash-table/issues/655

I would like to use the value data_previous for changes from callbacks as well as for normal edits.

Workaround: data_previous is read only but data_timestamp is NOT. You can check the state of data_timestamp and if it is None, this is your initial load. then just output time.time() to your table’s data_timestamp

It appears data_previous is no longer read only. I was only able to get it to change by setting it from the callback.

@callback(
    output=[
        Output('limit-overrides-table', 'data'),
        Output('limit-overrides-table', 'data_previous'),
        Output('limit-overrides-table', 'selected_rows'),
    ],
    inputs=dict(
        submit_clicks=Input('input-submit-button', 'n_clicks'),
        clear_clicks=Input('input-clear-button', 'n_clicks'),
        limit_table_d=Input('overrides-table', 'data'),
        limit_table_sr=Input('overrides-table', 'selected_rows'),
    ),
    state=dict(
        limit_table_dp=State('overrides-table', 'data_previous'),
    ),
)