【问题标题】:Is it Possible to Use Multiple DT formatStyle functions in R Shiny?是否可以在 R Shiny 中使用多个 DT formatStyle 函数?
【发布时间】:2018-09-15 19:25:48
【问题描述】:

我想知道是否可以在 R Shiny 中使用多个 DT::formatStyle 函数。

我想实现颜色(分别为正数和负数的绿色和红色)以及突出显示最后一行以显示列总和。

这是我正在尝试使用的代码,但是我收到一个错误:

 DT::formatStyle(
      columns = cols,
      color = DT::styleInterval(0, c('red', 'green'))

 ) %>%
 DT::formatStyle(
       'metric',
       target = 'row',
       backgroundColor = styleEqual('Total', 'gray'))

【问题讨论】:

  • 你应该可以。您可以将多个formatSignif() 连接在一起,所以如果您不能对formatStyle() 做同样的事情,我会感到惊讶

标签: r dataframe shiny shiny-reactivity


【解决方案1】:

是的,?formatStyleon the github pages documentation 中甚至还有示例

library(dplyr)
library(DT)

datatable(mtcars) %>%
  formatStyle("am", color = styleEqual(1, "red")) %>%
  formatStyle("cyl", color = styleInterval(7, c("green", "blue")))

如果您可以提供测试数据和完整的最小工作示例,帮助会更容易。

【讨论】:

  • 如果列有 Infinity 值怎么办,我们可以让它识别为蓝色吗?
猜你喜欢
  • 2016-10-29
  • 2020-11-30
  • 1970-01-01
  • 1970-01-01
  • 2018-10-19
  • 2018-10-08
  • 1970-01-01
  • 2020-12-15
  • 1970-01-01
相关资源
最近更新 更多