glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
633 stars 80 forks source link

Update nested table in detail view Shiny #100

Open JohanWillemsenFreshforward opened 3 years ago

JohanWillemsenFreshforward commented 3 years ago

Hi,

Nice package. Using it a lot! I have a table with expandable rows. The detail view displays another reactable, but from a different data frame.

dataset <- unique(CO2[, c("Plant", "Type")])

reactable(dataset , details = function(index) {
  htmltools::div(style = "padding: 16px",
    reactable(iris[isolate(input$variable2),], outlined = TRUE) 
  )
})

In shiny I create this table as usual, and update it with updateReactable, where I filter this dataset on rows based on a input widget.

## ui
 reactableOutput("react_table1")
## server
updateReactable("react_table1", data = dataset)

However I can update the main table, but it appears that I cannot access the reactable inside the details argument. Is there a way I can make this table visible for Shiny, so I can update it using a slider, or selectInput? Thanks in advance!

glin commented 3 years ago

Yes, you can put a reactableOutput() in the details view, and the nested table will have a Shiny output ID:

reactable(dataset , details = function(index) {
  htmltools::div(style = "padding: 16px",
    reactableOutput("my_nested_table")
  )
})

updateReactable("my_nested_table", ...)

There's just one caveat: if you collapse the row details, the nested table will be removed, so changes from updateReactable() might be reset when you expand the details again. It doesn't work that well, and I'd recommend only using static tables in row details if possible.