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

Dash-table not refreshed in browser when adding table-rows using clientside_callback #794

Closed
@kkollsga

Description

@kkollsga

Hi,
I'm trying to add rows using clientside_callback. I'm encountering 2 issues:

  1. After appending the new row to the data object, the table is not refreshed with new rows. If I update cell values of already plotted cells, the display updates as expected, and if I delete a row the new rows appear. Is there a way to manually trigger a full table refresh from the clientside?
  2. n_clicks is not reset to 0 after the clientside event has been triggered. You can see that by selecting different cells in the table. Every time you do that after having clicked new row, additional rows are inserted to the data object.

Thanks =)

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

import pandas as pd
magic = pd.DataFrame(data=[[1,2,3,4],[1,2,3,4]],columns=["abra","ka","da","bra"])

app = dash.Dash()

app.layout = html.Div([
    dash_table.DataTable(
        id='table',
        columns=[{"name": i, "id": i} for i in magic.columns],
        data=magic.to_dict('records'),
        editable=True,
        row_deletable=True
    ),
    html.Button('Add Row', id='editing-rows-button', n_clicks=0)
])

app.clientside_callback(
    """
    function (selected,n_clicks,data,columns) {
        if (n_clicks > 0) {
            newRow = {}
            for (i in columns) {
                newRow[columns[i]['name']] = null
            }
            data.push(newRow)
        }
        console.log(n_clicks)
        console.log(data)
        return data
    }
    """,
    Output('table', 'data'),
    [Input('table', 'active_cell'), Input('editing-rows-button', 'n_clicks')],
    [State('table', 'data'), State('table', 'columns')]
)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions