【问题标题】:R Datatable - how to add cell triangles?R Datatable - 如何添加单元格三角形?
【发布时间】:2020-09-12 17:10:11
【问题描述】:

如何将 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 时,不是将整个单元格涂成红色,而是将单元格的右上角三角形涂上颜色。像这样:

【问题讨论】:

    标签: r shiny dt


    【解决方案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)'))
      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2017-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      相关资源
      最近更新 更多