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

Add median as one of the built-in aggregate functions for colDef #30

Closed
mattwarkentin opened this issue Feb 27, 2020 · 2 comments
Closed

Add median as one of the built-in aggregate functions for colDef #30

mattwarkentin opened this issue Feb 27, 2020 · 2 comments

Comments

@mattwarkentin
Copy link

@mattwarkentin mattwarkentin commented Feb 27, 2020

Hi @glin,

Wondering if it would be possible to add median() as a built-in aggregate function for colDef()? I know that the user can provide a custom JS() function to do this on their own, so I could probably dig up enough JS to get it working, but I think median would be nice to have as a built-in.

Actually, while I'm thinking of it, it would be nice to be able to pass R functions instead of/in addition to JS functions, if possible. That way one could pass the median function, or an anonymous function with some other aggregating capability. Thoughts?

@glin
Copy link
Owner

@glin glin commented Feb 28, 2020

Hi,

Thanks for the suggestion. Calculating the median is pretty straightforward, so I went ahead and added a "median" aggregate function in 86adb96. For example:

reactable(
  iris,
  groupBy = "Species",
  columns = list(Sepal.Length = colDef(aggregate = "median"))
)

Passing R functions would be really cool, and totally possible I think. There'd be limitations though. JS aggregate functions run on the fly and update with table changes. For example, the aggregated values update when you filter this table: https://glin.github.io/reactable/articles/examples.html#aggregated-cell-rendering. R aggregated values would have to be precalculated and never change. But it's pretty much the same trade-off as JS vs. R render functions - much easier to write custom aggregators as an R programmer. Thanks for that suggestion as well! I've added it to my to-do list, but feel free to file a separate issue for it.

@mattwarkentin
Copy link
Author

@mattwarkentin mattwarkentin commented Feb 29, 2020

Wow, thanks for the quick addition of the median!

Ahh yes, I did not think about how the JS functions update the table when it is modified. Well, perhaps an R function could still be passed with the knowledge that it cannot be dynamically updated once rendered. As you mention, this is just the standard expectation for any R vs. JS render functions. I can definitely think of some cool custom aggregators that I can write in R and wouldn't really know how to do in JS, only due to my own JS limitations.

Anyway, thanks for considering this! I will file its own issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.