I have a matrix M with positive values and negative values. I am trying to display as a table in shiny app, using the DT package. I would like to display the matrix with different colors. Positive numbers in red and negative numbers (for example).
So far, I only can add colours in a one-to-one way . But I want to add colours in this way: if matrix_values > 0 "color1", if matrix_values < 0 "color2".
M <- matrix(c(-3:2), 3) # The matrix is more complex and it's created in a
reactive environment. Here is only an example
M_out <- reactive({
DT::datatable(M()) %>%
formatStyle(
columns = c(1:7),
backgroundColor = styleEqual(c( 0, 1), c("green", "red")
))
})
output$X_table_2 <- DT::renderDataTable(M_1X2())
Thanks !!