| --- |
| title: "cell_formatter_pdf" |
| author: "Hao" |
| date: "10/11/2017" |
| output: html_document |
| --- |
| |
| <script> |
| $( function() { |
| $( document ).tooltip(); |
| } ); |
| </script> |
| |
| |
| <div><div class = "tooltip">sss</div>ssa</div> |
| ```{r, include=F} |
| library(knitr) |
| library(kableExtra) |
| library(dplyr) |
| ``` |
| |
| ```{r} |
| mtcars[1:15, 1:5] %>% |
| mutate( |
| mpg = cell_spec(mpg, "html", color = "white", background = spec_color(mpg)), |
| disp = cell_spec(disp, "html", color = spec_color(disp, option = "B"), |
| bold = T, font_size = spec_font_size(disp)), |
| hp = cell_spec(hp, "html", tooltip = paste0("cyl:\n", cyl)) |
| ) %>% |
| kable("html", escape = F) %>% |
| kable_styling("condensed", full_width = F) |
| ``` |
| |
| ```{r} |
| iris[, 1:4] %>% |
| mutate_all(function(x){ |
| cell_spec(x, "html", |
| color = spec_color(x, option = "A"), |
| font_size = spec_font_size(x), |
| bold = T, tooltip = "1") |
| }) %>% |
| kable("html", escape = F, booktabs = T, linesep = "", align = "c")%>% |
| row_spec(0, angle = 270, align = "right") %>% |
| kable_styling(full_width = F) |
| ``` |
| |
| ```{r} |
| mtcars[1:10, 1:2] %>% |
| mutate( |
| car = row.names(.), |
| # You don't need format = "html" if you have ever defined options(knitr.table.format) |
| mpg = cell_spec(mpg, "html", bold = ifelse(mpg > 20, TRUE, FALSE)), |
| cyl = cell_spec(cyl, "html", color = "white", align = "c", angle = 45, |
| background = factor(cyl, c(4, 6, 8), |
| c("#666666", "#999999", "#BBBBBB"))) |
| ) %>% |
| select(car, mpg, cyl) %>% |
| knitr::kable("html", escape = F) %>% |
| kable_styling("striped", full_width = F) |
| ``` |