Hao Zhu | 6844920 | 2018-10-16 16:01:19 -0400 | [diff] [blame] | 1 | --- |
| 2 | title: "Using kableExtra in Radix" |
| 3 | description: | |
| 4 | A new article describing how to use kableExtra in Radix |
| 5 | author: |
| 6 | - name: Hao Zhu |
| 7 | url: https://github.com/haozhu233 |
| 8 | date: "`r Sys.Date()`" |
| 9 | output: radix::radix_article |
| 10 | --- |
| 11 | |
Hao Zhu | 72917f9 | 2019-03-15 18:41:42 -0400 | [diff] [blame] | 12 | **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. ** |
| 13 | |
| 14 | **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](https://github.com/haozhu233/kableExtra/blob/f3b6aa4bf1648979bbf48bb6f827755387eebed5/R/zzz.R#L23).** |
| 15 | |
Hao Zhu | 6844920 | 2018-10-16 16:01:19 -0400 | [diff] [blame] | 16 | 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)`. |
| 17 | |
Hao Zhu | 72917f9 | 2019-03-15 18:41:42 -0400 | [diff] [blame] | 18 | |
Hao Zhu | 6844920 | 2018-10-16 16:01:19 -0400 | [diff] [blame] | 19 | ```{r, echo = T} |
| 20 | library(kableExtra) |
Hao Zhu | 72917f9 | 2019-03-15 18:41:42 -0400 | [diff] [blame] | 21 | # options(kableExtra.html.bsTable = T) # No need for version 1.1.0+ |
Hao Zhu | 6844920 | 2018-10-16 16:01:19 -0400 | [diff] [blame] | 22 | |
| 23 | kable(iris[1:6, ], caption = "kable with kableExtra") %>% |
| 24 | kable_styling(c("striped", "hover", "condensed"), full_width = F, |
| 25 | position = "left") %>% |
| 26 | add_header_above(c("numerical" = 4, "categorical" = 1)) %>% |
| 27 | column_spec(1, bold = T) %>% |
| 28 | row_spec(0, italic = T) |
| 29 | ``` |
| 30 | |
| 31 | |
| 32 | Comparing with other table options |
| 33 | |
| 34 | ```{r, echo = T} |
| 35 | kable(iris[1:6, ], caption = "Basic kable") |
| 36 | ``` |
| 37 | |
| 38 | ```{r, echo = T} |
| 39 | rmarkdown::paged_table(iris) |
Hao Zhu | 6e63188 | 2018-10-16 16:33:10 -0400 | [diff] [blame] | 40 | ``` |
| 41 | |
| 42 | # Appendix |
| 43 | 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 |
| 44 | |
Hao Zhu | 72917f9 | 2019-03-15 18:41:42 -0400 | [diff] [blame] | 45 | ![](radix_no_bs.png) |