This function will put a HTML kable object in a fixed-height, fixed-width or both box and make it scrollable.
scroll_box(
kable_input,
height = NULL,
width = NULL,
box_css = "border: 1px solid #ddd; padding: 5px; ",
extra_css = NULL,
fixed_thead = TRUE
)
A HTML kable object
A character string indicating the height of the box, e.g. "50px"
A character string indicating the width of the box, e.g. "100px"
CSS text for the box
Extra CSS styles
HTML table option so table header row is fixed at top.
Values can be either T/F or list(enabled = T/F, background = "anycolor")
.
if (FALSE) {
# Specify table size by pixels
kable(cbind(mtcars, mtcars), "html") %>%
kable_styling() %>%
scroll_box(width = "500px", height = "200px")
# Specify by percent
kable(cbind(mtcars, mtcars), "html") %>%
kable_styling() %>%
scroll_box(width = "100%", height = "200px")
}
Run the code above in your browser using DataLab