I have a very simple issue. I am trying to conditionally color certain cells of a shiny
renderTable
. For some reason the method below is coloring one cell to the right and pushing the cells in the row over one column as well:
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)
Is this a bug? When I inspected the HTML output I saw it is leaving a blank <td> </td>
cell and creating a new <td style="background-color:red">
. I Also tried:
test[test$test1 == 1, "test1"] <- '<td bgcolor="#FF0000">1</td>'
This other styling works:
test[test$test1 == 1, "test1"] <- "<strong>1</strong>"
I am trying to avoid more complex solutions such as:
Is this too simple to work? Thank you so much.