% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/shiny.R
\name{updateReactable}
\alias{updateReactable}
\title{Update a reactable instance}
\usage{
updateReactable(
  outputId,
  data = NULL,
  selected = NULL,
  expanded = NULL,
  page = NULL,
  meta = NULL,
  session = NULL
)
}
\arguments{
\item{outputId}{The Shiny output ID of the \code{reactable} instance.}

\item{data}{Table data. A data frame or matrix.

\code{data} should have the same columns as the original table data.
When updating \code{data}, the selected rows, expanded rows, and current page
will reset unless explicitly specified. All other state will persist,
including sorting, filtering, and grouping state.}

\item{selected}{Selected rows. Either a numeric vector of row indices,
or \code{NA} to deselect all rows.}

\item{expanded}{Expanded rows. Either \code{TRUE} to expand all rows, or \code{FALSE}
to collapse all rows.}

\item{page}{The current page. A single, positive integer.}

\item{meta}{Custom table metadata. Either a named list with new values, or \code{NA}
to clear all metadata. New values are merged into the current metadata, so only
the values specified in \code{meta} will be updated.}

\item{session}{The Shiny session object. Defaults to the current Shiny session.}
}
\value{
None
}
\description{
\code{updateReactable()} updates a reactable instance within a Shiny application.
}
\examples{
# Run in an interactive R session
if (interactive()) {

library(shiny)
library(reactable)

data <- MASS::Cars93[, 1:7]

ui <- fluidPage(
  actionButton("select_btn", "Select rows"),
  actionButton("clear_btn", "Clear selection"),
  actionButton("expand_btn", "Expand rows"),
  actionButton("collapse_btn", "Collapse rows"),
  actionButton("page_btn", "Change page"),
  selectInput("filter_type", "Filter type", unique(data$Type), multiple = TRUE),
  reactableOutput("table")
)

server <- function(input, output) {
  output$table <- renderReactable({
    reactable(
      data,
      filterable = TRUE,
      searchable = TRUE,
      selection = "multiple",
      details = function(index) paste("Details for row:", index)
    )
  })

  observeEvent(input$select_btn, {
    # Select rows
    updateReactable("table", selected = c(1, 3, 5))
  })

  observeEvent(input$clear_btn, {
    # Clear row selection
    updateReactable("table", selected = NA)
  })

  observeEvent(input$expand_btn, {
    # Expand all rows
    updateReactable("table", expanded = TRUE)
  })

  observeEvent(input$collapse_btn, {
    # Collapse all rows
    updateReactable("table", expanded = FALSE)
  })

  observeEvent(input$page_btn, {
    # Change current page
    updateReactable("table", page = 3)
  })

  observe({
    # Filter data
    filtered <- if (length(input$filter_type) > 0) {
      data[data$Type \%in\% input$filter_type, ]
    } else {
      data
    }
    updateReactable("table", data = filtered)
  })
}

shinyApp(ui, server)
}

}
