Renders an interactive DT table with column-level filters and returns a
reactive containing only the currently visible (filtered) rows. This
reactive can be passed directly to any plotting module as its data
argument.
Arguments
- id
The ID for the Shiny module. Must match the
idused indataFilterUI().- data
A
reactivecontaining the data frame to display and filter.- factor.char.cols
Logical. When
TRUE, all character columns indataare converted to factors before the table is rendered. This causes DT to display select-box filters for those columns instead of free-text search boxes. Defaults toTRUE.- page.length
Integer. The default number of rows shown per page. Defaults to
10.
Value
A reactive expression that evaluates to the filtered subset of
data based on the current DT selection/filter state. Pass this
reactive to a plotting module's data argument to keep the plot in
sync with the table filters.
Examples
library(shiny)
library(VizModules)
ui <- fluidPage(
dataFilterUI("filter"),
verbatimTextOutput("rows")
)
server <- function(input, output, session) {
data <- reactive(iris)
filtered <- dataFilterServer("filter", data, factor.char.cols = TRUE)
output$rows <- renderPrint(nrow(filtered()))
}
if (interactive()) shinyApp(ui, server)