1

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

David
  • 9,216
  • 4
  • 45
  • 78
  • 1
    Not an answer to the question but the package DT has inbuilt download button. – s_baldur Sep 21 '22 at 13:55
  • 1
    I would be able to get this working with DT, but due to some other functionality, Id prefer to use reactable throughout the app. Thanks for the comment though! – David Sep 21 '22 at 14:13

1 Answers1

2

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)
David
  • 9,216
  • 4
  • 45
  • 78