plotly / plotly/dash

selected_row_ids property of DataTable is None in callback after refreshing a persisted table

Open
#1,850 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug dash-data-table P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Describe your context

I'm running Dash app from a python program.

  • replace the result of pip list | grep dash below
dash                              2.0.0
dash-bootstrap-components         1.0.0
dash-core-components              2.0.0
dash-html-components              2.0.0
dash-renderer                     1.9.1
dash-table                        5.0.0
dash-ui                           0.4.0
  • if frontend related, tell us your Browser, Version and OS

    • OS: Windows 10
    • Browser Firefox, Chrome
    • Version 94, 96 (respectively)
Describe the bug

My app has a DataTable and a callback that renders Tabs based on rows selected in the table. I've enabled persistence recently and I find that after a page refresh in the browser, the row selection is persisted in the table but the selected_row_ids are empty when passed to my callback.

Steps to reproduce:
  1. Store the program below in a python file.
  2. Run the file with dependencies as show above.
  3. In the browser a table will be shown. Choose a few rows using their checkboxes.
  4. Notice that the id's of the selected rows are now listed below the table.
  5. Refresh the page.

Code:

import dash
import dash_table
import pandas as pd
from dash import Input, Output
from dash import html

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")
df.insert(loc=0, column="id", value=range(0, 8))
app = dash.Dash(__name__)

app.layout = html.Div(
    [
        dash_table.DataTable(
            id="table",
            columns=[{"name": i, "id": i} for i in df.columns],
            data=df.to_dict("records"),
            persistence=True,
            row_selectable="multi",
            cell_selectable=False,
        ),
        html.Div(id="output"),
    ]
)

@app.callback(
    Output("output", "children"),
    Input("table", "selected_row_ids"),
)
def render_plot_tabs_from_selected_experiments_table_rows(
    selected_row_ids,
):
    return f"Output: {selected_row_ids}"

if __name__ == "__main__":
    app.run_server(debug=True)
Expected behavior

After the page is refreshed, when the callback function is invoked, the argument selected_row_ids should contain the ids of rows that are selected. These values should appear in the output div on screen.

Actual behavior

While selected rows still show as selected in the table, the value of selected_row_ids is None in the callback. The list of values appears empty below the table.

Screenshots
Expected:

image

Actual:

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python reproduction, focusing on the DataTable persistence behavior and the callback input selected_row_ids. The payload names no repository files or tests. Done means refreshing the page preserves the selected row IDs in the callback and displays them in the output div.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.