Get filtered data in reactable in shiny

Viewed 29

I have a shiny application that lets the user filter data, eventually the user should be able to download the filtered data but I cannot access the filtered/shown data from reactable.

An MWE would be the following: (Note that the getReactableState() function does not return the filtered data but would work if one had to select all filtered data.)

library(shiny)
library(reactable)

ui <- fluidPage(
  reactableOutput("table"),
  verbatimTextOutput("table_state")
)

server <- function(input, output) {
  output$table <- renderReactable({
    reactable(iris, filterable = TRUE)
  })
  
  output$table_state <- renderPrint({
    print(getReactableState("table")) #< wrong code here...
    # the goal would be to get the rows which are currently shown here 
  })
}
shinyApp(ui, server)

enter image description here

1 Answers

Not a full answer, but at least it allows to download the filtered data as a CSV (solution from here):

tags$button("Download as CSV", onclick = "Reactable.downloadDataCSV('table')")

The full solution looks like this:

library(shiny)
library(reactable)

ui <- fluidPage(
  tags$button("Download as CSV", onclick = "Reactable.downloadDataCSV('table')"),
  reactableOutput("table")
)

server <- function(input, output) {
  output$table <- renderReactable({
    reactable(iris, filterable = TRUE)
  })
}
shinyApp(ui, server)
Related