带有数据表的数据条

Data bars with Data tables

我正尝试按照以下步骤在 table 的列中添加数据栏:

library(DT)
options(DT.options = list(pageLength = 5))
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>% formatStyle(names(df),
  background = styleColorBar(range(df), 'lightblue'),
  backgroundSize = '98% 88%',
  backgroundRepeat = 'no-repeat',
  backgroundPosition = 'center')

条形图在单元格中从右到左显示,我希望它们从左到右显示。 data table 内可以做些什么来修改这些数据条。

angle 个参数 styleColorBar 应该完成这项工作

library(DT)
options(DT.options = list(pageLength = 5))
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>% formatStyle(names(df),
                              background = styleColorBar(range(df), 'lightblue', angle = -90),
                              backgroundSize = '98% 88%',
                              backgroundRepeat = 'no-repeat',
                              backgroundPosition = 'center')

来自help("styleColorBar")

angle a number of degrees representing the direction to fill the gradient relative to a horizontal line and the gradient line, going counter-clockwise. For example, 90 fills right to left and -90 fills left to right