{"action":"created","issue":{"url":"https://api.github.com/repos/yihui/knitr/issues/974","labels_url":"https://api.github.com/repos/yihui/knitr/issues/974/labels{/name}","comments_url":"https://api.github.com/repos/yihui/knitr/issues/974/comments","events_url":"https://api.github.com/repos/yihui/knitr/issues/974/events","html_url":"https://github.com/yihui/knitr/issues/974","id":61731712,"number":974,"title":"Support conditional formatting","user":{"login":"renkun-ken","id":4662568,"avatar_url":"https://avatars.githubusercontent.com/u/4662568?v=3","gravatar_id":"","url":"https://api.github.com/users/renkun-ken","html_url":"https://github.com/renkun-ken","followers_url":"https://api.github.com/users/renkun-ken/followers","following_url":"https://api.github.com/users/renkun-ken/following{/other_user}","gists_url":"https://api.github.com/users/renkun-ken/gists{/gist_id}","starred_url":"https://api.github.com/users/renkun-ken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renkun-ken/subscriptions","organizations_url":"https://api.github.com/users/renkun-ken/orgs","repos_url":"https://api.github.com/users/renkun-ken/repos","events_url":"https://api.github.com/users/renkun-ken/events{/privacy}","received_events_url":"https://api.github.com/users/renkun-ken/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-15T02:28:42Z","updated_at":"2015-03-15T19:12:25Z","closed_at":null,"body":"Consider the following example:\r\n\r\n```rconsole\r\n> library(knitr)\r\n> df <- data.frame(name = c(\"James\", \"Ken\", \"Jenny\"), age = c(18, 20, 22))\r\n> kable(df)\r\n\r\n|name  | age|\r\n|:-----|---:|\r\n|James |  18|\r\n|Ken   |  20|\r\n|Jenny |  22|\r\n```\r\n\r\nIs there a recommended way to transform the output to a html table with conditional formatting like\r\n\r\n```\r\n|name | age|\r\n|:----|---:|\r\n|James|<span style=\"background-color:#ffffff;\">18</span>|\r\n|Ken  |<span style=\"background-color:#ffffaa;\">20</span>|\r\n|Jenny|<span style=\"background-color:#ffff85;\">22</span>|\r\n```\r\n\r\nso that the background color of cells in column `age` gives a visual indicator of the magnitude of the cell value relative to other cells in the same column.\r\n\r\nOne other possible use case is to make red texts in all `age` cells whose value >= 20 so that the produced code is\r\n\r\n```\r\n|name | age|\r\n|:----|---:|\r\n|James|  18|\r\n|Ken  |<span style=\"color:red;\">20</span>|\r\n|Jenny|<span style=\"color:red;\">22</span>|\r\n```\r\n\r\nBasically, the feature may require that `kable` allow for some intermediate intervention by functions that transform the text to be put into the cell given its column name and its original value (e.g. numeric value). \r\n"},"comment":{"url":"https://api.github.com/repos/yihui/knitr/issues/comments/81203301","html_url":"https://github.com/yihui/knitr/issues/974#issuecomment-81203301","issue_url":"https://api.github.com/repos/yihui/knitr/issues/974","id":81203301,"user":{"login":"yihui","id":163582,"avatar_url":"https://avatars.githubusercontent.com/u/163582?v=3","gravatar_id":"","url":"https://api.github.com/users/yihui","html_url":"https://github.com/yihui","followers_url":"https://api.github.com/users/yihui/followers","following_url":"https://api.github.com/users/yihui/following{/other_user}","gists_url":"https://api.github.com/users/yihui/gists{/gist_id}","starred_url":"https://api.github.com/users/yihui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yihui/subscriptions","organizations_url":"https://api.github.com/users/yihui/orgs","repos_url":"https://api.github.com/users/yihui/repos","events_url":"https://api.github.com/users/yihui/events{/privacy}","received_events_url":"https://api.github.com/users/yihui/received_events","type":"User","site_admin":false},"created_at":"2015-03-15T19:12:25Z","updated_at":"2015-03-15T19:12:25Z","body":"That sounds a job more appropriate to the [DT](https://github.com/rstudio/DT) package instead of the `kable()` function. I do not want to make `kable()` too fancy."}}