I want to know how to assign a conditional format to a table so that each row has a different condition that needs to be fulfilled. So that in statistic row, if the value <0.96 it turns red, and in the case of p-value row if the value is > 0.05 it turns red.
I'm formatting from the following dataframe
df_try
Normal Jan Feb
1 stistic 0.93069466 0.90404849
2 p-values 0.05123532 0.01056474
My condition formatting is in the code imporvement_formatter but naturally, it turns all values red because all are <0.96. I need a second condition for the next row that works for the >0.05 condition
i2 <- df_try %>%
+ select(c(`Normal`,`Jan`, `Feb`))
> formattable(i2)
improvement_formatter <-
+ formatter("span",
+ style = x ~ style(
+ font.weight = "bold",
+ color = ifelse(x < 0.96, customRed, "black")))
>
> formattable(i2, align =c("l","c","c"), list(
+ `Indicator Name` =
+ formatter("span", style = ~ style(color = "grey",font.weight = "bold")),
+ `Jan` = improvement_formatter
+ ))
Have a look at the
area
function. It helps to use formatters on rows and not just on columns. So you can define your formatters like you did and then use them specificly on certain rows and columns. Here is an example: