Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Last active July 20, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadenbuie/7d8bb61476dcfa4459fb6e8b7a219022 to your computer and use it in GitHub Desktop.
Save gadenbuie/7d8bb61476dcfa4459fb6e8b7a219022 to your computer and use it in GitHub Desktop.
library(reactable)
narrow_mpg <- ggplot2::mpg[c("manufacturer", "year", "model")]
js_aggregate1 <- JS(
"function(values, rows) {
var yrmin = Math.min(...values)
var yrmax = Math.max(...values)
return [yrmin, yrmax.toString().slice(-2)].join(' - ')
}"
)
js_aggregate2 <- JS(
"function (values, rows) {
let low = values[0]
let high = values[0]
for (let v of values) {
if (v < low) low = v
if (v > high) high = v
}
return [low, high.slice(-2)].join(' - ')
}"
)
reactable(
narrow_mpg,
groupBy = "manufacturer",
columns = list(
year = colDef("Year", aggregate = js_aggregate1),
model = colDef("Model", aggregate = "unique")
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment