reactable()
creates a data table from tabular data with sorting
and pagination by default. The data table is an HTML widget that can be
used in R Markdown documents and Shiny applications, or viewed from an
R console.
reactable(
data,
columns = NULL,
columnGroups = NULL,
rownames = NULL,
groupBy = NULL,
sortable = TRUE,
resizable = FALSE,
filterable = FALSE,
searchable = FALSE,
searchMethod = NULL,
defaultColDef = NULL,
defaultColGroup = NULL,
defaultSortOrder = "asc",
defaultSorted = NULL,
pagination = TRUE,
defaultPageSize = 10,
showPageSizeOptions = FALSE,
pageSizeOptions = c(10, 25, 50, 100),
paginationType = "numbers",
showPagination = NULL,
showPageInfo = TRUE,
minRows = 1,
paginateSubRows = FALSE,
details = NULL,
defaultExpanded = FALSE,
selection = NULL,
selectionId = NULL,
defaultSelected = NULL,
onClick = NULL,
highlight = FALSE,
outlined = FALSE,
bordered = FALSE,
borderless = FALSE,
striped = FALSE,
compact = FALSE,
wrap = TRUE,
showSortIcon = TRUE,
showSortable = FALSE,
class = NULL,
style = NULL,
rowClass = NULL,
rowStyle = NULL,
fullWidth = TRUE,
width = "auto",
height = "auto",
theme = getOption("reactable.theme"),
language = getOption("reactable.language"),
elementId = NULL
)
A data frame or matrix.
Can also be a crosstalk::SharedData
object that wraps a data frame.
Named list of column definitions. See colDef()
.
List of column group definitions. See colGroup()
.
Show row names? Defaults to TRUE
if the data has row names.
To customize the row names column, use ".rownames"
as the column name.
Cells in the row names column are automatically marked up as row headers for assistive technologies.
Character vector of column names to group by.
To aggregate data when rows are grouped, use the aggregate
argument in colDef()
.
Enable sorting? Defaults to TRUE
.
Enable column resizing?
Enable column filtering?
Enable global table searching?
Custom search method to use for global table searching.
A JS()
function that takes an array of row objects, an array of
column IDs, and the search value as arguments, and returns the filtered
array of row objects.
Default column definition used by every column. See colDef()
.
Default column group definition used by every column group.
See colGroup()
.
Default sort order. Either "asc"
for ascending
order or "desc"
for descending order. Defaults to "asc"
.
Character vector of column names to sort by default.
Or to customize sort order, a named list with values of "asc"
or "desc"
.
Enable pagination? Defaults to TRUE
.
Default page size for the table. Defaults to 10.
Show page size options?
Page size options for the table. Defaults to 10, 25, 50, 100.
Pagination control to use. Either "numbers"
for page
number buttons (the default), "jump"
for a page jump, or "simple"
to show
'Previous' and 'Next' buttons only.
Show pagination? Defaults to TRUE
if the table has more
than one page.
Show page info? Defaults to TRUE
.
Minimum number of rows to show per page. Defaults to 1.
When rows are grouped, paginate sub rows? Defaults to FALSE
.
Additional content to display when expanding a row. An R function
that takes the row index and column name as arguments, or a JS()
function
that takes a row info object as an argument. Can also be a colDef()
to
customize the details expander column.
Expand all rows by default?
Enable row selection? Either "multiple"
or "single"
for
multiple or single row selection.
To get the selected rows in Shiny, use getReactableState()
.
To customize the selection column, use ".selection"
as the column name.
Shiny input ID for the selected rows. The selected rows are
given as a numeric vector of row indices, or NULL
if no rows are selected.
NOTE: selectionId
will be deprecated in a future release.
Use getReactableState()
to get the selected rows in Shiny instead.
A numeric vector of default selected row indices.
Action to take when clicking a cell. Either "expand"
to expand
the row, "select"
to select the row, or a JS()
function that takes a
row info object, column object, and table state object as arguments.
Highlight table rows on hover?
Add borders around the table?
Add borders around the table and every cell?
Remove inner borders from table?
Add zebra-striping to table rows?
Make tables more compact?
Enable text wrapping? If TRUE
(the default), long text will be
wrapped to multiple lines. If FALSE
, text will be truncated to fit on one line.
Show a sort icon when sorting columns?
Show an indicator on sortable columns?
Additional CSS classes to apply to the table.
Inline styles to apply to the table. A named list or character string.
Note that if style
is a named list, property names should be camelCased.
Additional CSS classes to apply to table rows. A character
string, a JS()
function that takes a row info object and table state object
as arguments, or an R function that takes a row index argument.
Inline styles to apply to table rows. A named list, character
string, JS()
function that takes a row info object and table state object
as arguments, or an R function that takes a row index argument.
Note that if rowStyle
is a named list, property names should be camelCased.
If rowStyle
is a JS()
function, it should return a JavaScript object with
camelCased property names.
Stretch the table to fill the full width of its container?
Defaults to TRUE
.
Width of the table in pixels. Defaults to "auto"
for automatic sizing.
To set the width of a column, see colDef()
.
Height of the table in pixels. Defaults to "auto"
for automatic sizing.
Theme options for the table, specified by
reactableTheme()
. Defaults to the global reactable.theme
option.
Can also be a function that returns a reactableTheme()
or NULL
.
Language options for the table, specified by
reactableLang()
. Defaults to the global reactable.language
option.
Element ID for the widget.
A reactable
HTML widget that can be used in R Markdown documents
and Shiny applications, or viewed from an R console.
See the online documentation for additional details and examples.
renderReactable()
and reactableOutput()
for using reactable
in Shiny applications or interactive R Markdown documents.
colDef()
, colFormat()
, and colGroup()
to customize columns.
reactableTheme()
and reactableLang()
to customize the table.
# Basic usage
reactable(iris)
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator
# Grouping and aggregation
reactable(
iris,
groupBy = "Species",
columns = list(
Sepal.Length = colDef(aggregate = "count"),
Sepal.Width = colDef(aggregate = "mean"),
Petal.Length = colDef(aggregate = "sum"),
Petal.Width = colDef(aggregate = "max")
)
)
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator
# Row details
reactable(iris, details = function(index) {
htmltools::div(
"Details for row: ", index,
htmltools::tags$pre(paste(capture.output(iris[index, ]), collapse = "\n"))
)
})
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator
# Conditional styling
reactable(sleep, columns = list(
extra = colDef(style = function(value) {
if (value > 0) {
color <- "green"
} else if (value < 0) {
color <- "red"
} else {
color <- "#777"
}
list(color = color, fontWeight = "bold")
})
))
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator