Last active
July 20, 2020 17:12
-
-
Save gadenbuie/9ce3a58a7f6109c23cdd68711a2623ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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