plotly / plotly/dash

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

Aperta
#1,850 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug dash-data-table P3
Lingua principale
Python
Stelle
24.4k
Fork
2.3k
Merge medio
2g 7h
PR unite (30g)
13

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione Python fornita, concentrandoti sul comportamento di persistenza di DataTable e sull’input del callback selected_row_ids. Il payload non nomina file o test del repository. Il lavoro è completato quando il ricaricamento della pagina mantiene gli ID delle righe selezionate nel callback e li visualizza nel div di output.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
frontend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.