I currently want to use colorformatting for my dataFrame
s using shiny
and the DT
package. My table looks roughly like this.
| val1 | val2 |
| ---------|------ |
| a | b |
| a | a |
| b | b |
I want to change the textcolor of val1
as red whenever val1[i] == val2[i]
is satisfied. So the resulting table should look like this.
| val1 | val2 |
| ---------|------ |
| a | b |
| a* | a | * = red
| b* | b |
From the documentation, I see that conditional formatting can be applied with DT::formatstyle
. However, the conditions specified there must be dependent on one single column of the table. Of course, I could create a new column with
dat$condition = ( val1 == val2 )
but then this column is also displayed in the widget which I don't want to happen. (Unless there is a way of removing columns of datatables
objects). I am looking for a function addcolor_conditional
that does something like this
condition_vector = ( val1 == val2 )
datatable( mtcars ) %>% addcolor_conditional(
condition_vector, color = "red" )
Any help would be appreciated