glin / reactable

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

Keep expanded rows after data update #268

Open maxmoro opened 2 years ago

maxmoro commented 2 years ago

Is it possible to keep the currently expanded/compressed rows after the data refresh? (via updateReactable) I see from the help that this is not currently possible, I guess because the data may change in a way the previous expanded rows are not available after the refresh, or the grouped cells have been altered.

I'm thinking if the package can use a rule that allows to keep the expanded rows if the grouped columns are not changed and no row has been added/removed.

Thank you for this great library, it is really useful!

glin commented 2 years ago

It's possible in just the one case where you have all rows expanded. You can use updateReactable(data = ..., expanded = TRUE) to re-expand all rows when updating data. But otherwise, expanded state is intentionally not preserved because, you're right, the previous expanded rows may be different or not even exist in the new data. There's no way to tell if the new data should be considered the exact same set of rows, so we just reset everything to be safe and prevent UI weirdness.

Interesting idea to keep expanded rows if the grouped cells haven't changed though..

Before v0.3.0, that would've hard to do because grouped row expanded state was tracked using row indices. But since v0.3.0, grouped row expanded state is now tracked using column IDs and cell values, so something like { 'Type:Midsize': true } for an expanded "Midsize" cell in the "Type" column. Preserving expanded state here would probably make sense now.

There might be other edge cases to consider though, like preserving expanded row details would still be tricky, or maybe the new data is a logically different dataset that just happens to have the same column ID and cell value. An option to tell updateReactable() that the new data is the same dataset could work, but also add more complexity. Thanks for the suggestion.

mbjohnsonmn commented 1 year ago

Mine is perhaps a related edge-case, as least in that it relates to controlling the default expansion of columns listed in groupBy. I list the first two columns of my df and so ensure they are always present in the date. I would like to default to only the first column expanded. Currently, I only find the option of none or all (both). Am I missing something? Thanks for a great package!

glin commented 1 year ago

@mbjohnsonmn You're not missing anything, and expansion is either all or nothing right now due to prior technical limitations. I've never thought of limiting expansion to certain columns (or I guess nesting level) though, and I think that's a really great idea.