Conditional formatting tables in RMarkdown documents

大憨熊 提交于 2019-12-03 03:09:06
Victorp

Hello here a solution using function FlexTable from package ReporteRs. This function is intended to create Word table but you can get the html code from FlexTable objects with as.html :

---
title: "Untitled"
output: html_document
---


```{r, results='asis', warning=FALSE, message=FALSE}
library(ReporteRs)
data(iris)
irisFT = FlexTable( iris )

vars <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
for (i in vars) {
  irisFT[iris[, i] < 3, i] = cellProperties( background.color = "orange" )
  irisFT[iris[, i] >= 3 & iris[, i] < 3.5, i] = cellProperties( background.color = "yellow" )
  irisFT[iris[, i] > 4, i] = cellProperties( background.color = "#81DAF5" )
}

cat(as.html(irisFT))
```

For more example, please visit https://davidgohel.github.io/ReporteRs/articles/FlexTable.html

knitr contain vignette with jQuery DataTables example.

vignette("datatables", package = "knitr")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!