Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.