Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Color the values from one cell along a gradient based upon percentiles
- # instead of the values themselves
- # Do this for all columns
- library(formattable)
- library(scales)
- mydf <- data.frame(A = round(runif(10, 0, 100), 0),
- B = round(runif(10, 0, 100), 0),
- C = round(runif(10, 0, 100), 0),
- stringsAsFactors = FALSE)
- do_thing <- function(.x) {
- result <- lapply(names(.x), function(n) {
- formatter("span",
- style = ~ style(color = scales::div_gradient_pal()(ecdf(mydf[,n])(mydf[,n]))))
- })
- names(result) <- names(.x)
- result
- }
- formattable(mydf, do_thing(mydf))
Add Comment
Please, Sign In to add comment