posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.3k stars 78 forks source link

Rendered datatable losses ability to select row with collapsing sidebar #1104

Open corey-dawson opened 9 months ago

corey-dawson commented 9 months ago

When outputting a dataframe via ui.output_data_frame and specifying row_selection_mode, a row in the datatable can be selected. However, when pairing with a sidebar, the user's ability to select a row is lost after collapsing or expanding the sidebar. Ability to select row only returns when app is refreshed

Current Version:

Python: 3.10.13 Shiny: 0.6.0

Steps to recreate (via example below)

  1. Launch app
  2. Select row in datatable. Row is indicated selected
  3. Collapse sidebar. Selected row is not longer selected. User cannot select a new row

Example

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
import pandas as pd
df = pd.DataFrame({
    'A': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar', 'bar', 'bar'],
    'B': ['one', 'one', 'two', 'two', 'one', 'one', 'two', 'two'],
    'C': ['small', 'large', 'large', 'small', 'small', 'small', 'large', 'small'],
    'D': [1, 2, 2, 3, 3, 4, 5, 6],
    'E': [2, 4, 5, 5, 6, 6, 8, 9]
})

app_ui = ui.page_fluid(
    ui.layout_sidebar(
        ui.sidebar(
            ui.input_slider("n", "N", min=0, max=100, value=20),
            title="A title",
        ),
        ui.output_data_frame("tbl_out"),
        style="min-height: 100vh;"
    )
)

def server(input: Inputs, output: Outputs, session: Session):

    @render.data_frame
    def tbl_out():
        return render.DataTable(
            df,
            row_selection_mode="single"
        )

app = App(app_ui, server)
corey-dawson commented 9 months ago

Updated to Shiny version 0.7.1 with same result