getReactableState: Get the state of a reactable instance

Description Usage Arguments Value Examples

View source: R/shiny.R

Description

getReactableState() gets the state of a reactable instance within a Shiny application.

Usage

1
getReactableState(outputId, name = NULL, session = NULL)

Arguments

outputId

The Shiny output ID of the reactable instance.

name

Name of a state value to get. One of "page", "pageSize", "pages", or "selected". If unspecified, all values will be returned in a named list.

session

The Shiny session object. Defaults to the current Shiny session.

Value

If name is specified, one of the following values:

If name is unspecified, getReactableState() returns a named list containing all values.

If the table has not been rendered yet, getReactableState() returns NULL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Run in an interactive R session
if (interactive()) {

library(shiny)
library(reactable)

ui <- fluidPage(
  actionButton("prev_page_btn", "Previous page"),
  actionButton("next_page_btn", "Next page"),
  reactableOutput("table"),
  verbatimTextOutput("table_state")
)

server <- function(input, output) {
  output$table <- renderReactable({
    reactable(
      iris,
      showPageSizeOptions = TRUE,
      selection = "multiple"
    )
  })

  output$table_state <- renderPrint({
    state <- req(getReactableState("table"))
    print(state)
  })

  observeEvent(input$prev_page_btn, {
    # Change to the previous page
    page <- getReactableState("table", "page")
    if (page > 1) {
      updateReactable("table", page = page - 1)
    }
  })

  observeEvent(input$next_page_btn, {
    # Change to the next page
    state <- getReactableState("table")
    if (state$page < state$pages) {
      updateReactable("table", page = state$page + 1)
    }
  })
}

shinyApp(ui, server)
}

reactable documentation built on Jan. 13, 2021, 8:55 a.m.