0

How can I format DT::datatable cells to have a triangle - similar to this question for html tables: How to add triangle in table cell

Here are examples where the datatable has entire cells coloured, https://rstudio.github.io/DT/010-style.html however I just want the top right (or left) triangle area to be coloured.

Here's an example of styling cells background colour that I'd like changed to only colour the top right triangle:

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'))
)

Instead of the whole cell coloured red when it is value == 1, just colour the top right triangle of the cell. Like this:

enter image description here

Vlad
  • 3,058
  • 4
  • 25
  • 53

1 Answers1

1

Here you go

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)'))
  )
mosk915
  • 696
  • 1
  • 7
  • 16