Chapter 9 Graphical tables–interactive tables, highlights, and sparklines

library(tidyverse)
library(DT)

datatable(mpg, options = list(pageLength = 5), filter = 'top')

9.1 Heatmap table

From https://rstudio.github.io/DT/010-style.html

df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) %>%
  {paste0("rgb(255,", ., ",", ., ")")}
datatable(df) %>% formatStyle(names(df), backgroundColor = styleInterval(brks, clrs))

9.2 Table lens with a integrated bar

datatable(df) %>% formatStyle(names(df),
  background = styleColorBar(range(df), 'lightblue'),
  backgroundSize = '98% 88%',
  backgroundRepeat = 'no-repeat',
  backgroundPosition = 'center')