formatting - Conditionally coloring a cell in htmlTable for R -


i'm using excellent htmltable package printing results in rmarkdown. 1 of tables shows values between 0 1. have generated vector of 100 colors interpolated between white (#ffffff) , red (#ff5555) i'd match each cell's background depending on it's value.

the logical part clear me (multiply cell's value 100, round , extract color corresponding index of color vector).

what i'm not sure is, having matched color each cell, how make htmltable paint it?

thanks!

i think can using rgb colors like:

paste0("background-color:rgb(255, ",value*255," , ",value*255 ," )"  

where value cell value 0 1

example( 0 red,1 white)

 df = as.data.frame(matrix(round(runif(15, 0, 1), 1),ncol = 3 ))  htmltable::htmltable(df,css.cell=apply(df,c(1,2),function(i)paste0("background-color:rgb(255, ",round(i*255,0)," , ",round(i*255,0) ," )"))) 

enter image description here


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -