Skip to content

Data Grid column width doesn't work for wide dataframes #1825

@gshotwell

Description

@gshotwell

Seems like there's some kind of conflict between scrolling data grids horizontally and setting the column width, I'd expect the first column in both of these grids to be the same width.

from shiny import App, render, ui
import polars as pl
import numpy as np

# Create a DataFrame with 50 columns
df = pl.DataFrame({f"col_{i}": np.random.randn(100) for i in range(50)})

app_ui = ui.page_fillable(
    ui.card(ui.output_data_frame("wide_df")),
    ui.card(ui.output_data_frame("narrow_df")),
)


style = [
    {
        "cols": [0],
        "style": {"width": "500px"},
    }
]


def server(input, output, session):
    @render.data_frame
    def wide_df():
        return render.DataGrid(
            df,
            filters=True,
            styles=style,
        )

    @render.data_frame
    def narrow_df():
        return render.DataGrid(
            df.select(pl.col("^col_[0-3]$")), filters=True, styles=style
        )


app = App(app_ui, server)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions