【发布时间】:2017-02-03 05:06:32
【问题描述】:
我有一个非常简单的问题。我正在尝试有条件地为shinyrenderTable 的某些单元格着色。出于某种原因,下面的方法是将一个单元格向右着色,并将行中的单元格也推到一列上:
test <- data.frame(test1 = c(1:3), test2 = c(4:6))
test[test$test1 == 1, "test1"] <- '<td style="background-color:red">'
library(shiny)
ui <- shinyUI(fluidPage(
tableOutput("tt")
)
)
server <- shinyServer(function(input, output) {
output$tt <- renderTable({
test
}, sanitize.text.function = function(x) x)
})
shinyApp(ui = ui, server = server)
这是一个错误吗?当我检查 HTML 输出时,我看到它留下了一个空白的<td> </td> 单元格并创建了一个新的<td style="background-color:red">。我也试过了:
test[test$test1 == 1, "test1"] <- '<td bgcolor="#FF0000">1</td>'
其他样式有效:
test[test$test1 == 1, "test1"] <- "<strong>1</strong>"
我试图避免更复杂的解决方案,例如:
这是否太简单而无法工作?非常感谢。
【问题讨论】:
-
您只想使用 renderTable?或者可能是 HtmlTable 或 DT ?
-
@Batanichek 为简单起见,我想坚持使用 renderTable。如果做不到,我可以使用其他函数和包(看起来 DT 是用于表格的方式,所以我可能还是应该开始学习它)。