【发布时间】:2019-03-01 19:12:49
【问题描述】:
我在这里开了一个关于如何在数据表中添加范围栏的帖子:Programmatically color format numeric columns in a datatable。
但是,我不想根据整个数据框拟合范围,而是根据每个单独列的范围进行格式化。我想出了一些有效的代码,但是,它绝对是令人生畏的,而不是程序化的。
library(magrittr)
library(DT)
# Specify numeric columns
foo <- sapply(iris, is.numeric)
datatable(iris, filter = 'top', options = list(pageLength = 5, autoWidth = TRUE)) %>%
formatStyle(names(iris)[foo][1],
background = styleColorBar(range(iris[, 1]), 'lightblue'),
backgroundSize = '98% 88%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center') %>%
formatStyle(names(iris)[foo][2],
background = styleColorBar(range(iris[, 2]), 'green'),
backgroundSize = '98% 88%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center')
【问题讨论】:
标签: r shiny datatables dt