3

I'm using the reactable package in R to display data sorted by multiple groups. Is there a way to display the sum of all counts of all given subgroups?

Here is an example:

data("diamonds")
diamonds$id <- 1:nrow(diamonds)
reactable::reactable(data = diamonds[1:1000, c("cut", "color", "id")],
                     striped = TRUE,
                     highlight = TRUE,
                     bordered = TRUE,
                     showPageSizeOptions = TRUE,
                     groupBy = c("cut", "color"), 
                     columns = list(
                       id = reactable::colDef(aggregate = "count")
                     ))

So the first row in the ID column refers to the 7 subgroups in the ideal group. Instead of showing the amount of existing subgroups I want reactable to display the sum of all subgroup counts in the first row. So sum(67, 7, 42, 57, 46, 73, 41)

Is there a way to do this?

enter image description here

Eike
  • 98
  • 5
  • 3
    I think you need to update `reactable` package. Try running `devtools::install_github("glin/reactable")` in `Console`. You will need the `devtools` package as well. Then, `Session` -> `Restart R`, and run your code again. Your code will return desired output (ex.: Ideal id 333, Premium id 290, etc.) in `id` column/row. – Radovan Miletić Dec 09 '21 at 12:06
  • 2
    Thats it. Thanks! @RadovanMiletić – Eike Dec 09 '21 at 12:11

1 Answers1

0

It's a known issue and it was fixed in this commit. Just follow Radovan's instructions, and it will work as expected.

Try running devtools::install_github("glin/reactable") in Console. You will need the devtools package as well. Then, Session -> Restart R, and run your code again.

> packageVersion("reactable")
[1] ‘0.2.3.9000’

enter image description here

Maksim I. Kuzmin
  • 1,170
  • 7
  • 16