R Datatable - 如何添加单元格三角形?
R Datatable - how to add cell triangles?
如何将 DT::datatable 个单元格设置为三角形 - 类似于 html 表的这个问题:How to add triangle in table cell
以下是数据表中整个单元格都被着色的示例,https://rstudio.github.io/DT/010-style.html
但是我只希望右上(或左)三角形区域被着色。
这是我希望更改为仅为右上角三角形着色的样式单元格背景颜色的示例:
library(DT)
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>%
formatStyle(
'V6',
backgroundColor = styleEqual(c(0, 1), c('transparent', 'red'))
)
当值 == 1 时,不是将整个单元格着色为红色,而是将单元格的右上角三角形着色。像这样:
给你
library(DT)
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>%
formatStyle(
'V6',
backgroundImage = styleEqual(c(0, 1), c('transparent', 'linear-gradient(225deg, red, red 6px, transparent 6px, transparent)'))
)
如何将 DT::datatable 个单元格设置为三角形 - 类似于 html 表的这个问题:How to add triangle in table cell
以下是数据表中整个单元格都被着色的示例,https://rstudio.github.io/DT/010-style.html 但是我只希望右上(或左)三角形区域被着色。
这是我希望更改为仅为右上角三角形着色的样式单元格背景颜色的示例:
library(DT)
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>%
formatStyle(
'V6',
backgroundColor = styleEqual(c(0, 1), c('transparent', 'red'))
)
当值 == 1 时,不是将整个单元格着色为红色,而是将单元格的右上角三角形着色。像这样:
给你
library(DT)
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>%
formatStyle(
'V6',
backgroundImage = styleEqual(c(0, 1), c('transparent', 'linear-gradient(225deg, red, red 6px, transparent 6px, transparent)'))
)