I'm working on a shiny-app that produces and sends a pdf-report, containing the wrangled data. The problem is that I can't get the table layout to look as the client want it to look.
The client wants the tables to lack lines/borders except ontop of the last row, is this possible in kable and/or kableExtra? No answers containing other packages please, as I'm aware that of xtable.
table.tbl <- tibble(var1 = c("entry 1", "entry 2", "entry 3", "entry 4"),
var2 = c(2000, 1000, 3000, 200),
var3 = c(3000, 2000, 4000, 100))
table.tbl %>%
kable("latex",
booktabs = T) %>%
row_spec((table.tbl %>%
nrow()-1), hline_after = T)
The kable() function in knitr is a very simple table generator, and is simple by design. It only generates tables for strictly rectangular data such as matrices and data frames. You cannot heavily format the table cells or merge cells.
Kable is a 3PL Provider Who Helps E-Retailers, Subscription Box Companies, and Consumer Brands Succeed Wherever You Sell-Your Website, Amazon, or Online Marketplaces.
Upon installing, inserttable registers a new RStudio Addin (Insert Table) that can be used to easily insert a table in a Rmd document. To use it, open a Rmd or R document and select “Addins –> Insert Table”.
I think kable
is meant to be super simple and so lacks features like this by design. That said, I have come up with an absurdly painful solution. The gist is that I set border colours to white (I'm assuming your page is white), then switch line colours to non-white (red in my example) when needed, then back to white again afterwards.
Initially, add the following to your YAML header:
header-includes:
- \usepackage{colortbl}
Next, in your document add:
\arrayrulecolor{white}
To render the table use:
library(tidyverse)
library(knitr)
library(kableExtra)
table.tbl <- tibble(var1 = c("entry 1", "entry 2", "entry 3", "entry 4"),
var2 = c(2000, 1000, 3000, 200),
var3 = c(3000, 2000, 4000, 100))
table.tbl %>%
kable(format = "latex") %>%
row_spec((table.tbl %>%
nrow()-1), extra_latex_after = "\\arrayrulecolor{red}") %>%
row_spec((table.tbl %>%
nrow()), extra_latex_after = "\\arrayrulecolor{white}")
giving,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With