【发布时间】:2014-11-28 06:07:53
【问题描述】:
在另一个post 中,假设该表不是renderUI 函数的一部分,已回答了相同的问题。
在下面的示例中,我正在尝试调整相同的解决方案(使用 JQuery),其中我想要有条件地格式化的表属于 renderUI 函数。
library(shiny)
library(datasets)
script <- "$('tbody tr td:nth-child(5)').each(function() {
var cellValue = $(this).text();
if (cellValue > 50) {
$(this).css('background-color', '#0c0');
}
else if (cellValue <= 50) {
$(this).css('background-color', '#f00');
}
})"
shinyServer(function(input, output, session) {
session$onFlushed(function() {
session$sendCustomMessage(type='jsCode', list(value = script))
})
output$view <- renderTable({
head(rock, n = 20)
})
output$Test1 <- renderUI({
list(
tags$head(tags$script(HTML('Shiny.addCustomMessageHandler("jsCode", function(message) { eval(message.value); });'))),
tableOutput("view")
)
})
})
shinyUI(fluidPage(
tabsetPanel(
tabPanel("Test1",uiOutput("Test1")),
tabPanel("Test2")
)
))
在这个小例子中,条件格式不应用于表格
【问题讨论】: