I need to create a few tables in an R Markdown HTML report, for dataframes which are wider than a page. kable (which is my to-go solution for tables in R Markdown - I'm a simple guy) doesn't do a great job: the table just continues and "disappears" through the right-hand side of the page. pander (which on my system is available as an import from skimr) looks better:
---
title: "Untitled"
author: "anon"
date: "`r Sys.Date()`"
output: html_document
# output: html_vignette
---
```{r setup, include=FALSE}
library(skimr)
library(dplyr)
knitr::opts_chunk$set(echo = TRUE)
```
test
```{r }
set.seed(1)
df <- matrix(rnorm(120), 3, 40)
index <- sample(1:120,30)
df[index] <- NA
df <- data.frame(df)
pander(df %>% summarize_all(function(x) sum(is.na(x))/length(x) * 100))
```
but I was looking for something with a little bit more "oomph". Specifically, I'd like the headers row to be colored in light grey. I get the desired color if I change the output: html_document line in the YAML header to output: html_vignette, however I also get ugly-looking irregular line breaks, unlike for output: html_document where all lines had the same length:
Any suggestions? Ideally, the package/solution should be simple - I don't need very fancy effects, just a constant width (like in output: html_document ) but a colored header. Also, since my numbers are "percentage of missingness", as you can see, it would be great if I could either add a title to the table, or add % symbols after each entry.