Hao Zhu | 9ce317e | 2017-10-12 18:19:55 -0400 | [diff] [blame] | 1 | --- |
| 2 | title: "cell_formatter_pdf" |
| 3 | author: "Hao" |
| 4 | date: "10/11/2017" |
| 5 | output: html_document |
| 6 | --- |
| 7 | |
Hao Zhu | 064990d | 2017-10-17 18:08:42 -0400 | [diff] [blame] | 8 | <script> |
| 9 | $( function() { |
| 10 | $( document ).tooltip(); |
| 11 | } ); |
| 12 | </script> |
| 13 | |
| 14 | |
| 15 | <div><div class = "tooltip">sss</div>ssa</div> |
Hao Zhu | 9ce317e | 2017-10-12 18:19:55 -0400 | [diff] [blame] | 16 | ```{r, include=F} |
| 17 | library(knitr) |
| 18 | library(kableExtra) |
| 19 | library(dplyr) |
| 20 | ``` |
| 21 | |
| 22 | ```{r} |
| 23 | mtcars[1:15, 1:5] %>% |
| 24 | mutate( |
| 25 | mpg = cell_spec(mpg, "html", color = "white", background = spec_color(mpg)), |
| 26 | disp = cell_spec(disp, "html", color = spec_color(disp, option = "B"), |
| 27 | bold = T, font_size = spec_font_size(disp)), |
Hao Zhu | 064990d | 2017-10-17 18:08:42 -0400 | [diff] [blame] | 28 | hp = cell_spec(hp, "html", tooltip = paste0("cyl:\n", cyl)) |
Hao Zhu | 9ce317e | 2017-10-12 18:19:55 -0400 | [diff] [blame] | 29 | ) %>% |
| 30 | kable("html", escape = F) %>% |
| 31 | kable_styling("condensed", full_width = F) |
| 32 | ``` |
Hao Zhu | 457acb4 | 2017-10-14 17:37:02 -0400 | [diff] [blame] | 33 | |
| 34 | ```{r} |
| 35 | iris[, 1:4] %>% |
| 36 | mutate_all(function(x){ |
| 37 | cell_spec(x, "html", |
| 38 | color = spec_color(x, option = "A"), |
| 39 | font_size = spec_font_size(x), |
Hao Zhu | 064990d | 2017-10-17 18:08:42 -0400 | [diff] [blame] | 40 | bold = T, tooltip = "1") |
Hao Zhu | 457acb4 | 2017-10-14 17:37:02 -0400 | [diff] [blame] | 41 | }) %>% |
| 42 | kable("html", escape = F, booktabs = T, linesep = "", align = "c")%>% |
| 43 | row_spec(0, angle = 270, align = "right") %>% |
| 44 | kable_styling(full_width = F) |
| 45 | ``` |
Hao Zhu | b1de967 | 2018-01-08 16:29:24 -0500 | [diff] [blame] | 46 | |
| 47 | ```{r} |
| 48 | mtcars[1:10, 1:2] %>% |
| 49 | mutate( |
| 50 | car = row.names(.), |
| 51 | # You don't need format = "html" if you have ever defined options(knitr.table.format) |
| 52 | mpg = cell_spec(mpg, "html", bold = ifelse(mpg > 20, TRUE, FALSE)), |
| 53 | cyl = cell_spec(cyl, "html", color = "white", align = "c", angle = 45, |
| 54 | background = factor(cyl, c(4, 6, 8), |
| 55 | c("#666666", "#999999", "#BBBBBB"))) |
| 56 | ) %>% |
| 57 | select(car, mpg, cyl) %>% |
| 58 | knitr::kable("html", escape = F) %>% |
| 59 | kable_styling("striped", full_width = F) |
| 60 | ``` |