Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Other changes

* `@render.data_frame` now properly fills its container by default. (#1126)

* We improved the accessibility of the full screen toggle button in cards created with `ui.card(full_screen=True)`. Full-screen cards are now also supported on mobile devices. (#1129)

* When entering and exiting full-screen card mode, Shiny now emits a client-side custom `bslib.card` event that JavaScript-oriented users can use to react to the full screen state change. (#1129)
Expand Down
22 changes: 15 additions & 7 deletions js/dataframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface ShinyDataGridProps<TIndex> {
const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {
const { id, data, bgcolor } = props;
const { columns, type_hints, data: rowData } = data;
const { width, height, filters: withFilters } = data.options;
const { width, height, fill, filters: withFilters } = data.options;

const containerRef = useRef<HTMLDivElement>(null);
const theadRef = useRef<HTMLTableSectionElement>(null);
Expand Down Expand Up @@ -213,10 +213,13 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {

const headerRowCount = table.getHeaderGroups().length;

const scrollingClass =
containerRef.current?.scrollHeight > containerRef.current?.clientHeight
? "scrolling"
: "";
// Assume we're scrolling until proven otherwise
let scrollingClass = "scrolling";
const scrollHeight = containerRef.current?.scrollHeight;
const clientHeight = containerRef.current?.clientHeight;
if (scrollHeight && clientHeight && scrollHeight <= clientHeight) {
scrollingClass = "";
}

const makeHeaderKeyDown =
(column: Column<unknown[], unknown>) => (event: React.KeyboardEvent) => {
Expand All @@ -227,12 +230,17 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {

const measureEl = useVirtualizerMeasureWorkaround(rowVirtualizer);

let className = `shiny-data-grid ${containerClass} ${scrollingClass}`;
if (fill) {
className += " html-fill-item";
}

return (
<>
<div
className={`shiny-data-grid ${containerClass} ${scrollingClass}`}
className={className}
ref={containerRef}
style={{ width, maxHeight: height, overflow: "auto" }}
style={{ width, height, overflow: "auto" }}
>
<table
className={tableClass + (withFilters ? " filtering" : "")}
Expand Down
21 changes: 21 additions & 0 deletions js/dataframe/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

.shiny-data-grid {
max-width: 100%;
height: 500px;
&:not(.scrolling) {
height: auto;
}

> table {
border-collapse: separate;
Expand Down Expand Up @@ -198,3 +202,20 @@
}
}
}

/* Center the table when inside of a card */
.card-body .shiny-data-grid {
margin-left: auto;
margin-right: auto;
}


/* When .shiny-data-grid is not scrolling, the containers shouldn't flex */
shiny-data-frame {
&:has(> div > .shiny-data-grid:not(.scrolling)) {
flex: 0 0 auto;
}
> div:has(> .shiny-data-grid:not(.scrolling)) {
flex: 0 0 auto;
}
}
1 change: 1 addition & 0 deletions js/dataframe/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface DataGridOptions {
filters?: boolean;
width?: string;
height?: string;
fill?: boolean;
}

export interface PandasData<TIndex> {
Expand Down
7 changes: 4 additions & 3 deletions shiny/render/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class DataGrid(AbstractTabularData):
A pandas `DataFrame` object, or any object that has a `.to_pandas()` method
(e.g., a Polars data frame or Arrow table).
width
A _maximum_ amount of vertical space for the data grid to occupy, in CSS units
A _maximum_ amount of horizontal space for the data grid to occupy, in CSS units
(e.g. `"400px"`) or as a number, which will be interpreted as pixels. The
default is `fit-content`, which sets the grid's width according to its contents.
Set this to `100%` to use the maximum available horizontal space.
height
A _maximum_ amount of vertical space for the data grid to occupy, in CSS units
(e.g. `"400px"`) or as a number, which will be interpreted as pixels. If there
are more rows than can fit in this space, the grid will scroll. Set the height
to `None` to allow the grid to grow to fit all of the rows (this is not
to `"auto"` to allow the grid to grow to fit all of the rows (this is not
recommended for large data sets, as it may crash the browser).
summary
If `True` (the default), shows a message like "Viewing rows 1 through 10 of 20"
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(
data: object,
*,
width: str | float | None = "fit-content",
height: Union[str, float, None] = "500px",
height: Union[str, float, None] = None,
summary: Union[bool, str] = True,
filters: bool = False,
row_selection_mode: Literal["none", "single", "multiple"] = "none",
Expand Down Expand Up @@ -113,6 +113,7 @@ def to_payload(self) -> Jsonifiable:
filters=self.filters,
row_selection_mode=self.row_selection_mode,
style="grid",
fill=self.height is None,
)
return res

Expand Down
26 changes: 22 additions & 4 deletions shiny/www/shared/py-shiny/dataframe/dataframe.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions shiny/www/shared/py-shiny/dataframe/dataframe.js.map

Large diffs are not rendered by default.