Using kableExtra in Radix

A new article describing how to use kableExtra in Radix

Hao Zhu https://github.com/haozhu233
2019-03-15

Starting from kableExtra 1.1.0, you don’t need to turn on this option as it’s turned on by default for Radix and gitbook, for everyone’s convenience. This Documentation is here to help you understand the logics behind the scene.

If you want to this kind of native support to other html format, please submit a PR and add the template name to this line.

People may find some features in kableExtra, such as hovering/striped rows are not working in radix. The reason is that kableExtra relies on bootstrap stylesheet to do these jobs while radix doesn’t have those css load. Therefore you need to tell kableExtra to load the table css for you by setting options(kableExtra.html.bsTable = T).


library(kableExtra)
# options(kableExtra.html.bsTable = T)  # No need for version 1.1.0+

kable(iris[1:6, ], caption = "kable with kableExtra") %>%
  kable_styling(c("striped", "hover", "condensed"), full_width = F,
                position = "left") %>%
  add_header_above(c("numerical" = 4, "categorical" = 1)) %>%
  column_spec(1, bold = T) %>%
  row_spec(0, italic = T)
Table 1: kable with kableExtra
numerical
categorical
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa

Comparing with other table options


kable(iris[1:6, ], caption = "Basic kable")
Table 2: Basic kable
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa

rmarkdown::paged_table(iris)

Appendix

Here is a screenshot of how table looks like if you don’t turn on the kableExtra.html.bsTable option (with the same code). In fact, the only part that breaks is the striped and hover option. :P