gpt4 book ai didi

r Shiny - DataTableOutput - 颜色特定的行和列

转载 作者:行者123 更新时间:2023-12-01 12:32:42 24 4
gpt4 key购买 nike

有没有办法为 r Shiny 的 dataTableOutput 中的特定行着色?

我发现我可以设置 orderClasses = TRUE 为有序列着色,但我想始终为输出数据表的第 2 列和第 2 行着色。我一直在阅读选项手册,但没有找到任何东西。

- - - - - -编辑 - - - - - - -

好的,在 Yihui 和 user5029763 的建议之后,我现在可以使用 DT 突出显示列,但是我仍然无法突出显示行。这是我使用 iris 数据集作为示例的代码 - 如果 Species 是 setosa,我在这里尝试突出显示整行,但是,在我的计算机上,它只突出显示了 setosa 的单元格:

datatable(iris) %>% formatStyle(
'Species',
target = 'row',
backgroundColor = styleEqual('setosa', 'gray')
)

enter image description here

- - - - 编辑 - - - - - - - - - - - -

抱歉,这篇文章太长了 - 事实上,我运行了这里指定的确切代码: http://rstudio.github.io/DT/010-style.html
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(
'V6',
target = 'row',
backgroundColor = styleEqual(c(0, 1), c('gray', 'yellow'))
)

它仍然只突出显示我的计算机上的单元格而不是行。我正在使用 RStudio 的 3.2.1 版和 0.99.447 版。我也有 github 版本的 Shiny ,不确定这是否会覆盖数据表中的任何选项?

最佳答案

Yihui 发布的链接很好地解释了 formatStyle,但我认为那里没有提到“目标”这个论点。

要为整行着色,请使用参数 target="row"formatStyle .

关于r Shiny - DataTableOutput - 颜色特定的行和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32103377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com