R/downloadableReactTable.R
downloadableReactTable.Rd
Server-side function for the downloadableReactTableUI.
downloadableReactTable(
id,
table_data,
selection_mode = NULL,
pre_selected_rows = NULL,
file_name_root = "data_file",
download_data_fxns = NULL,
pagination = FALSE,
table_height = 600,
show_rownames = FALSE,
columns_filter = FALSE,
global_search = TRUE,
row_highlight = TRUE,
row_striping = TRUE,
table_options = list(),
logger = NULL
)
the ID of the Module's UI element
reactive expression (or parameter-less function) that acts as table data source
to enable row selection, set selection_mode
value to either "single" for single row
selection or "multiple" for multiple rows selection, case insensitive. Any other value will
disable row selection. Row selection will be enabled by radio buttons in "single" selection
and checkboxes in "multiple" selection (default = NULL)
reactive expression (or parameter-less function) provides the rows indices of the rows to be selected when the table is rendered. If selection_mode is disabled, this parameter will have no effect. If selection_mode is "single" only the first row index will be used (default = NULL)
the base name used for user-downloaded file. It can be either a character string a reactive expression or a function returning a character string (default = 'data_file')
a named list of functions providing the data as return values. The names for the list should be the same names as the ones used in the downloadableReactTableUI (default = NULL)
to enable table pagination (default = FALSE)
max table height in pixels. Vertical scroll will be shown after that height value
enable displaying rownames as a separate column (default = FALSE)
enable the filtering input on each column in the table (default = FALSE)
enable table global searching input to search and filter in all columns at once (default = TRUE)
enable highlighting rows upon mouse hover (default = TRUE)
add zebra-striped style to table rows (default = TRUE)
optional table formatting parameters check ?reactable::reactable
for options full list.
Also see example below to see how to pass options (default = list())
logger to use (default = NULL)
A named list of two elements:
selected_rows: data.frame of current selected rows
table_state: a list of the current table state. The list keys are
("page", "pageSize", "pages", "sorted" and "selected").
Review ?reactable::getReactableState
for more info.
This function is not called directly by consumers - it is accessed in
server.R using the same id provided in downloadableReactTableUI
:
downloadableReactTable(id)
if (interactive()) {
library(shiny)
library(periscope2)
library(reactable)
shinyApp(
ui = fluidPage(fluidRow(column(
width = 12,
downloadableReactTableUI(
id = "object_id1",
downloadtypes = c("csv", "tsv"),
hovertext = "Download the data here!")))),
server = function(input, output) {
table_state <- downloadableReactTable(
id = "object_id1",
table_data = reactiveVal(iris),
download_data_fxns = list(csv = reactiveVal(iris), tsv = reactiveVal(iris)),
selection_mode = "multiple",
pre_selected_rows = function() {c(1, 3, 5)},
table_options = list(columns = list(
Sepal.Length = colDef(name = "Sepal Length"),
Sepal.Width = colDef(filterable = TRUE),
Petal.Length = colDef(show = FALSE),
Petal.Width = colDef(defaultSortOrder = "desc")),
theme = reactableTheme(
borderColor = "#dfe2e5",
stripedColor = "#f6f8fa",
highlightColor = "#f0f5f9",
cellPadding = "8px 12px")))
observeEvent(table_state(), { print(table_state()) })
})
}