| Title: | 'MUI X Data Grid' for 'shiny' Apps and 'Quarto' |
|---|---|
| Description: | Provides access to 'MUI X Data Grid', a fast and extensible React data table and React data grid, with filtering, sorting, pagination, and more. Bundles the MIT-licensed community edition of the '@mui/x-data-grid' JavaScript library (the commercial 'Pro' and 'Premium' tiers are not included). |
| Authors: | Felix Luginbuhl [aut, cre, cph] (ORCID: <https://orcid.org/0009-0008-6625-2899>), MUI [cph] (Copyright holder of the bundled '@mui/x-data-grid', '@mui/x-virtualizer', '@mui/x-internals', '@mui/private-theming' and '@mui/styled-engine' JavaScript libraries), Meta Platforms, Inc. and affiliates [cph] (Copyright holder of the bundled 'react-is' JavaScript library; 'react' and 'react-dom' are declared as peer dependencies and provided at runtime by 'shiny.react') |
| Maintainer: | Felix Luginbuhl <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-06-20 17:30:15 UTC |
| Source: | https://github.com/cran/muiDataGrid |
DataGrid
DataGrid(rows = NULL, columns = NULL, ...)DataGrid(rows = NULL, columns = NULL, ...)
rows |
A data.frame of rows. An |
columns |
Column definitions (list of lists, or a data.frame with one
row per column). If |
... |
Additional props passed directly to the MUI DataGrid component. |
A shiny.react element (also classed muiDataGrid) that
renders the MUI X Data Grid. Use it directly in Shiny UI, inside
renderReact(), or in a Quarto/R Markdown document.
# Minimal: column definitions are auto-generated from the data frame. DataGrid(rows = head(iris)) # Custom columns plus an initial page size of 5 rows. DataGrid( rows = head(mtcars), columns = list( list(field = "mpg", headerName = "MPG"), list(field = "cyl", headerName = "Cylinders") ), initialState = list( pagination = list(paginationModel = list(pageSize = 5)) ) )# Minimal: column definitions are auto-generated from the data frame. DataGrid(rows = head(iris)) # Custom columns plus an initial page size of 5 rows. DataGrid( rows = head(mtcars), columns = list( list(field = "mpg", headerName = "MPG"), list(field = "cyl", headerName = "Cylinders") ), initialState = list( pagination = list(paginationModel = list(pageSize = 5)) ) )
A DataGrid component with server-side pagination, sorting, and filtering. The component sends pagination, sort, and filter state to R via a Shiny input.
DataGridServer( inputId, rows = NULL, columns = NULL, rowCount = NULL, loading = NULL, initialPageSize = NULL, pageSizeOptions = NULL, filterDebounce = NULL, ... )DataGridServer( inputId, rows = NULL, columns = NULL, rowCount = NULL, loading = NULL, initialPageSize = NULL, pageSizeOptions = NULL, filterDebounce = NULL, ... )
inputId |
Character. The Shiny input ID. When pagination, sorting, or
filtering changes, the new state is available as |
rows |
A data.frame. Pass the full dataset (like
|
columns |
Column definitions (list of lists). If NULL, auto-generated
from |
rowCount |
Integer. When provided, |
loading |
Logical. Whether to show the loading indicator. If
|
initialPageSize |
Integer. Convenience for setting the initial page
size. Builds MUI's |
pageSizeOptions |
Integer vector. Available page size options. If
|
filterDebounce |
Integer. Milliseconds to debounce filter input before
sending state to R. If |
... |
Additional props passed directly to the MUI DataGrid component.
Note: |
Pass the full dataset via rows — just like DataGrid() —
and DataGridServer() handles pagination, sorting, and filtering
automatically. For manual control (e.g. database queries), supply
pre-sliced rows together with an explicit rowCount.
A shiny.react element.
Experimental. DataGridServer() (together with
processGridParams) is specific to this R package and has
no equivalent in MUI X Data Grid: MUI ships only the building blocks
(paginationMode = "server" plus callbacks) and leaves the data layer
to you. This wrapper supplies that layer in R, and in doing so encodes a
number of opinionated decisions that may change in future releases. Pin the
package version if you rely on the current behavior. Decisions worth
knowing about:
Mode is selected by the presence of rowCount: supply it to
pass a pre-sliced page (manual mode); omit it to let the full
rows be paginated automatically.
Changing the sort or any filter resets the grid to the first page.
Unrecognized filter operators pass all rows through with a warning
(see processGridParams).
When rows has no id column, ids are generated
positionally and are not stable across sort/filter changes.
Supply a stable, unique id column if you use row selection.
initialPageSize, initialState, and any initial sort or
filter seed the grid only on the first render. The React component
reads them once when it mounts, so changing them reactively afterwards
(e.g. from a selectInput) has no effect on the already-mounted
grid. To change page size after mount, drive it from the grid's own
controls rather than re-rendering with a new initialPageSize.
## Not run: # Simple usage: pass the full dataset, pagination is handled automatically output$grid <- renderReact({ DataGridServer("grid_params", rows = my_data, initialPageSize = 10L, pageSizeOptions = c(10L, 25L, 50L) ) }) # Manual usage: handle pagination yourself (e.g. database queries) output$grid <- renderReact({ result <- processGridParams(my_data, input$grid_params, pageSize = 10L) DataGridServer("grid_params", rows = result$rows, rowCount = result$rowCount, initialPageSize = 10L, pageSizeOptions = c(10L, 25L, 50L) ) }) ## End(Not run)## Not run: # Simple usage: pass the full dataset, pagination is handled automatically output$grid <- renderReact({ DataGridServer("grid_params", rows = my_data, initialPageSize = 10L, pageSizeOptions = c(10L, 25L, 50L) ) }) # Manual usage: handle pagination yourself (e.g. database queries) output$grid <- renderReact({ result <- processGridParams(my_data, input$grid_params, pageSize = 10L) DataGridServer("grid_params", rows = result$rows, rowCount = result$rowCount, initialPageSize = 10L, pageSizeOptions = c(10L, 25L, 50L) ) }) ## End(Not run)
Mui X Data Grid UI JS dependency
muiDataGridDependency()muiDataGridDependency()
A list of HTML dependency objects (htmltools::htmlDependency)
that load the bundled MUI X Data Grid JavaScript and its shared MUI
Material runtime. Attach it to custom HTML when building a grid by hand.
# Inspect the dependencies attached to every DataGrid() element. muiDataGridDependency()# Inspect the dependencies attached to every DataGrid() element. muiDataGridDependency()
When called interactively, renders the component in the IDE viewer panel. Otherwise, falls back to standard shiny.tag printing (raw HTML text).
## S3 method for class 'muiDataGrid' print(x, browse = interactive(), ...)## S3 method for class 'muiDataGrid' print(x, browse = interactive(), ...)
x |
A muiDataGrid object (also inherits shiny.tag). |
browse |
Whether to render in viewer. Defaults to TRUE in interactive sessions. |
... |
Additional arguments passed to print. |
Invisibly returns x.
grid <- DataGrid(rows = head(iris)) # browse = FALSE prints the underlying HTML instead of opening the viewer. print(grid, browse = FALSE)grid <- DataGrid(rows = head(iris)) # browse = FALSE prints the underlying HTML instead of opening the viewer. print(grid, browse = FALSE)
Applies pagination, sorting, and filtering from DataGridServer
parameters to a data.frame. Use inside renderReact() with
input$<inputId> to get the current page of data.
processGridParams(data, params, pageSize = 100L)processGridParams(data, params, pageSize = 100L)
data |
A data.frame with all rows. |
params |
The grid params list from |
pageSize |
Page size to use when |
A list with rows (data.frame for the current page) and
rowCount (integer, total matching rows).
Experimental. This helper is specific to this R package and
has no equivalent in MUI X Data Grid, which leaves the server-side data
layer entirely to the developer. It reimplements MUI's server-mode
filtering and sorting semantics in R, so its behavior may change between
releases and can differ in edge cases from MUI's own client-side filtering.
Decisions worth knowing about: string filters are case-insensitive (except
is, which is case-sensitive), missing values always sort last, and
unrecognized filter operators pass all rows through with a warning.
df <- data.frame(name = paste("Row", 1:50), value = 1:50) # Initial render (no params yet) processGridParams(df, params = NULL, pageSize = 10) # Page 2, sorted descending, filtered params <- list( pagination_model = list(page = 1, pageSize = 10), sort_model = list(list(field = "value", sort = "desc")), filter_model = list(items = list( list(field = "value", operator = ">", value = "10") )) ) processGridParams(df, params)df <- data.frame(name = paste("Row", 1:50), value = 1:50) # Initial render (no params yet) processGridParams(df, params = NULL, pageSize = 10) # Page 2, sorted descending, filtered params <- list( pagination_model = list(page = 1, pageSize = 10), sort_model = list(list(field = "value", sort = "desc")), filter_model = list(items = list( list(field = "value", operator = ">", value = "10") )) ) processGridParams(df, params)