blob: 233c13ac7e8b39aeb6630a2efa8049572a80aa77 [file] [log] [blame]
Hao Zhu9ce317e2017-10-12 18:19:55 -04001---
2title: "cell_formatter_pdf"
3author: "Hao"
4date: "10/11/2017"
5output: html_document
6---
7
Hao Zhu064990d2017-10-17 18:08:42 -04008<script>
9 $( function() {
10 $( document ).tooltip();
11 } );
12</script>
13
14
15<div><div class = "tooltip">sss</div>ssa</div>
Hao Zhu9ce317e2017-10-12 18:19:55 -040016```{r, include=F}
17library(knitr)
18library(kableExtra)
19library(dplyr)
20```
21
22```{r}
23mtcars[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 Zhu064990d2017-10-17 18:08:42 -040028 hp = cell_spec(hp, "html", tooltip = paste0("cyl:\n", cyl))
Hao Zhu9ce317e2017-10-12 18:19:55 -040029 ) %>%
30 kable("html", escape = F) %>%
31 kable_styling("condensed", full_width = F)
32```
Hao Zhu457acb42017-10-14 17:37:02 -040033
34```{r}
35iris[, 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 Zhu064990d2017-10-17 18:08:42 -040040 bold = T, tooltip = "1")
Hao Zhu457acb42017-10-14 17:37:02 -040041 }) %>%
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 Zhub1de9672018-01-08 16:29:24 -050046
47```{r}
48mtcars[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```