-
Notifications
You must be signed in to change notification settings - Fork 179
Closed
Description
I need conditionally color the cells, but "<" or ">" can't be recognized by styleEqual. This is a question rather than an issue.
library(DT)
library(tidyverse)
copy.color <- data.frame(color = c("#4682b4", "#CDCDCD", "#00CC00", "#9ACC00", "#FFFF00", "#EAA211", "#FF4F00"), copy = c("0 copy", "< 1 copy", "1 copy", "1-2 copies", "2 copies", "2-3 copies", "> 3 copies"))
legend <- copy.color %>%
pivot_wider(names_from = color, values_from = copy)
DT::datatable(legend,
rownames = F,
options =
list(
autoWidth = F,
ordering = F,
dom = 'rt',
headerCallback = JS(
"function(thead, data, start, end, display){",
" $(thead).remove();",
"}"),
columnDefs = list(
list(className = 'dt-center', targets = "_all"),
list(width = '100px', targets = "_all")
)
)
) %>%
formatStyle(1:ncol(legend), backgroundColor = styleEqual(copy.color$copy, copy.color$color),
fontWeight = "bold")
By filing an issue to this repo, I promise that
- I have fully read the issue guide at https://yihui.name/issue/.
- I have provided the necessary information about my issue.
- If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
- If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included
xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('rstudio/DT'). - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- I have learned the Github Markdown syntax, and formatted my issue correctly.
I understand that my issue may be closed if I don't fulfill my promises.
