R Brilhante: formatação condicional da tabela dentro da renderUI

Noutropostar a mesma pergunta foi respondida assumindo que a tabela não faz parte de uma função renderUI.

No exemplo abaixo, estou tentando ajustar a mesma solução (usando JQuery) em que a tabela que eu quero formatar condicionalmente pertence a uma função 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")
    )
  ))

Neste pequeno exemplo, a formatação condicional não é aplicada à tabela

questionAnswers(2)

yourAnswerToTheQuestion