Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a vector of length of groups in aggregate #391

Open
olivroy opened this issue Aug 20, 2024 · 1 comment
Open

Accept a vector of length of groups in aggregate #391

olivroy opened this issue Aug 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@olivroy
Copy link

olivroy commented Aug 20, 2024

I am trying to add support for summary rows in gt and its wrapper for reactable (#1359). However, the aggregate argument is not flexible enough.

Since gt precomputes its summary values, I wonder if there is a way to just plug those in the aggregate argument.

library(gt)
library(reactable)
# # rstudio/gt#1359
gt <- exibble |>
  gt(groupname_col = "group") |>
  summary_rows(
    columns = num,
    fns = ~sum( .x ^ 2)
  )
sum <- extract_summary(gt)

exibble |> 
  reactable::reactable(
    groupBy = "group",
    columns = list(
      # create summary
      num = colDef(aggregate = "sum")
    )
  )

I wonder if there would be a way to pass values of the length of groups.

So that I could just plug the summary values that are computed in gt in the reactable call.

num_summary_vals <- extract_summary(gt)[[1]] |> purrr::map_dbl(~ .x$num)
exibble |> 
  reactable::reactable(
    groupBy = "group",
    columns = list(
      # create summary
      num = colDef(aggregate = num_summary_vals )
    )
  )

I'd be happy to contribute this to reactable with some guidance

@glin glin added the enhancement New feature or request label Sep 9, 2024
@glin
Copy link
Owner

glin commented Sep 9, 2024

It's not impossible, but I think it'd be very difficult just because all the grouping is done on the JavaScript side right now. You'd need a way to associate an aggregate value with a group, or make assumptions about how the grouping is done in JS, e.g. what order the groups are in.

I think the best way to do this would be to let you define both the row groups and the aggregate values at the same time in R, so you'd have full control over both the grouping and aggregation. That would be similar to other common requests for a "tree table" feature, so linking #391, #379, #112, #147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants