Add scroll_box
diff --git a/NAMESPACE b/NAMESPACE
index 905a515..a8af5b9 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -12,6 +12,7 @@
export(magic_mirror)
export(rmd_format)
export(row_spec)
+export(scroll_box)
export(usepackage_latex)
importFrom(knitr,knit_meta_add)
importFrom(magrittr,"%>%")
diff --git a/R/scroll_box.R b/R/scroll_box.R
new file mode 100644
index 0000000..166545d
--- /dev/null
+++ b/R/scroll_box.R
@@ -0,0 +1,29 @@
+#' Put a HTML table into a scrollable box
+#'
+#' @description This function will put a HTML kable object in a fixed-height,
+#' fixed-width or both box and make it scrollable.
+#'
+#' @param kable_input A HTML kable object
+#' @param height A character string indicating the height of the box, e.g. "50px"
+#' @param width A character string indicating the width of the box, e.g. "100px"
+#'
+#' @export
+scroll_box <- function(kable_input, height = NULL, width = NULL) {
+ kable_attrs <- attributes(kable_input)
+ out <- as.character(kable_input)
+ box_styles <- c()
+ if (!is.null(height)) {
+ box_styles <- c(box_styles,
+ paste0("overflow-y: scroll; height:", height, "; "))
+ }
+ if (!is.null(width)) {
+ box_styles <- c(box_styles,
+ paste0("overflow-x: scroll; width:", width, "; "))
+ }
+ out <- paste0('<div style="', paste(box_styles, collapse = ""), '">',
+ out, '</div>')
+ out <- structure(out, format = "html",
+ class = "knitr_kable")
+ attributes(out) <- kable_attrs
+ return(out)
+}
diff --git a/man/scroll_box.Rd b/man/scroll_box.Rd
new file mode 100644
index 0000000..e7fab72
--- /dev/null
+++ b/man/scroll_box.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/scroll_box.R
+\name{scroll_box}
+\alias{scroll_box}
+\title{Put a HTML table into a scrollable box}
+\usage{
+scroll_box(kable_input, height = NULL, width = NULL)
+}
+\arguments{
+\item{kable_input}{A HTML kable object}
+
+\item{height}{A character string indicating the height of the box, e.g. "50px"}
+
+\item{width}{A character string indicating the width of the box, e.g. "100px"}
+}
+\description{
+This function will put a HTML kable object in a fixed-height,
+fixed-width or both box and make it scrollable.
+}