1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#' htmlTable with pagination widget
#'
#' This widget renders a table with pagination into an htmlwidget
#'
#' @param x A data frame to be rendered
#' @param number_of_entries a numeric vector with the number of entries per page to show.
#' If there is more than one number given, the user will be able to show the number
#' of rows per page in the table.
#' @param ... Additional parameters passed to htmlTable
#' @inheritParams htmlwidgets::createWidget
#' @import htmlwidgets
#' @return an htmlwidget showing the paginated table
#' @export
htmlTableWidget <- function(x, number_of_entries = c(10, 25, 100),
width = NULL, height = NULL, elementId = NULL,
...) {
rendered_table <- htmlTable(x, ...)
# forward options and variables using the input list:
input <- list(
thetable = rendered_table,
options = list(number_of_entries = number_of_entries)
)
# create widget
htmlwidgets::createWidget(
name = "htmlTableWidget",
x = input,
width = width,
height = height,
package = "htmlTable",
elementId = elementId
)
}
#' Shiny bindings for htmlTableWidget
#'
#' Output and render functions for using htmlTableWidget within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like `'100%'`, `'400px'`, `'auto'`) or a number,
#' which will be coerced to a string and have `'px'` appended.
#' @param expr An expression that generates a [htmlTableWidget()]
#' @param env The environment in which to evaluate `expr`.
#' @param quoted Is `expr` a quoted expression (with `quote()`)? This
#' is useful if you want to save an expression in a variable.
#'
#' @name htmlTableWidget-shiny
#'
#' @examples
#' \dontrun{
#' # In the UI:
#' htmlTableWidgetOutput("mywidget")
#' # In the server:
#' renderHtmlTableWidget({
#' htmlTableWidget(iris)
#' })
#' }
#' @export
htmlTableWidgetOutput <- function(outputId, width = "100%", height = "400px") {
htmlwidgets::shinyWidgetOutput(outputId, "htmlTableWidget", width, height, package = "htmlTable")
}
#' @rdname htmlTableWidget-shiny
#' @export
renderHtmlTableWidget <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) {
expr <- substitute(expr)
} # force quoted
htmlwidgets::shinyRenderWidget(expr, htmlTableWidgetOutput, env, quoted = TRUE)
}
|