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.

setting selected_row_ids doesn't seem to initialied the selected row IDs #707

Open
@chriddyp

Description

@chriddyp

it should update the derived_viewport_selected_row_ids property and initialize the checkboxes in the table

import dash
from dash.dependencies import Input, Output
import dash_table
import dash_html_components as html
import dash_core_components as dcc
from app import app
import plotly.express as px
import pandas as pd

df = px.data.iris()  # sample dataset
df['id'] = df.index

app = dash.Dash(__name__)

app.layout = html.Div([

    dash_table.DataTable(
            data=df.to_dict('rows'),
            columns=[
                {'name': i, 'id': i}
                for i in df.columns
            ],
            style_table={'height': 500, 'overflowY': 'scroll'},
            filter_action='native',
            sort_action='native',
            id='data',
            editable=True,
            row_selectable='multi',
            selected_row_ids=[0, 1, 5]
        ),
    ], width=100),

    dcc.Graph('another-graph')
])


@app.callback(
    Output('another-graph', 'figure'),
    [Input('column-dropdown', 'value'),
     Input('data', 'derived_virtual_data'),
     Input('data', 'derived_viewport_selected_row_ids')]
)
def update_graph(column, rows, row_ids):
    print(row_ids)
    if rows is None:
        dff = df
    elif len(rows) == 0:
        return px.scatter()
    elif rows is not None:
        dff = pd.DataFrame(rows)
    dff['color'] = [
        'Selected' if i in row_ids else '' for i in range(len(dff))
    ]

    return px.bar(
        dff,
        x=dff.columns[0],
        y=column,
        hover_data=dff.columns,
        color='color',
        category_orders={'color': ['', 'Selected']}
    ).update_layout(showlegend=False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions