You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
6.7KB

  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/output.R
  3. \name{datatable}
  4. \alias{datatable}
  5. \alias{datatable.default}
  6. \alias{datatable.desctable}
  7. \title{Create an HTML table widget using the DataTables library}
  8. \usage{
  9. datatable(data, ...)
  10. \method{datatable}{default}(data, options = list(), class = "display",
  11. callback = DT::JS("return table;"), caption = NULL,
  12. filter = c("none", "bottom", "top"), escape = TRUE,
  13. style = "default", width = NULL, height = NULL, elementId = NULL,
  14. fillContainer = getOption("DT.fillContainer", NULL),
  15. autoHideNavigation = getOption("DT.autoHideNavigation", NULL),
  16. selection = c("multiple", "single", "none"), extensions = list(),
  17. plugins = NULL, ...)
  18. \method{datatable}{desctable}(data, options = list(paging = F, info = F,
  19. search = F, dom = "Brtip", fixedColumns = T, fixedHeader = T, buttons =
  20. c("copy", "excel")), class = "display",
  21. callback = DT::JS("return table;"), caption = NULL,
  22. filter = c("none", "bottom", "top"), escape = FALSE,
  23. style = "default", width = NULL, height = NULL, elementId = NULL,
  24. fillContainer = getOption("DT.fillContainer", NULL),
  25. autoHideNavigation = getOption("DT.autoHideNavigation", NULL),
  26. selection = c("multiple", "single", "none"),
  27. extensions = c("FixedHeader", "FixedColumns", "Buttons"),
  28. plugins = NULL, rownames = F, digits = 2, ...)
  29. }
  30. \arguments{
  31. \item{data}{a data object (either a matrix or a data frame)}
  32. \item{...}{arguments passed to \code{format}.}
  33. \item{options}{a list of initialization options (see
  34. \url{http://datatables.net/reference/option/}); the character options
  35. wrapped in \code{\link[htmlwidgets]{JS}()} will be treated as literal
  36. JavaScript code instead of normal character strings; you can also set
  37. options globally via \code{\link{options}(DT.options = list(...))}, and
  38. global options will be merged into this \code{options} argument if set}
  39. \item{class}{the CSS class(es) of the table; see
  40. \url{http://datatables.net/manual/styling/classes}}
  41. \item{callback}{the body of a JavaScript callback function with the argument
  42. \code{table} to be applied to the DataTables instance (i.e. \code{table})}
  43. \item{caption}{the table caption; a character vector or a tag object
  44. generated from \code{htmltools::tags$caption()}}
  45. \item{filter}{whether/where to use column filters; \code{none}: no filters;
  46. \code{bottom/top}: put column filters at the bottom/top of the table; range
  47. sliders are used to filter numeric/date/time columns, select lists are used
  48. for factor columns, and text input boxes are used for character columns; if
  49. you want more control over the styles of filters, you can provide a list to
  50. this argument of the form \code{list(position = 'top', clear = TRUE, plain
  51. = FALSE)}, where \code{clear} indicates whether you want the clear buttons
  52. in the input boxes, and \code{plain} means if you want to use Bootstrap
  53. form styles or plain text input styles for the text input boxes}
  54. \item{escape}{whether to escape HTML entities in the table: \code{TRUE} means
  55. to escape the whole table, and \code{FALSE} means not to escape it;
  56. alternatively, you can specify numeric column indices or column names to
  57. indicate which columns to escape, e.g. \code{1:5} (the first 5 columns),
  58. \code{c(1, 3, 4)}, or \code{c(-1, -3)} (all columns except the first and
  59. third), or \code{c('Species', 'Sepal.Length')}}
  60. \item{style}{the style name (\url{http://datatables.net/manual/styling/});
  61. currently only \code{'default'} and \code{'bootstrap'} are supported}
  62. \item{width}{Width/Height in pixels (optional, defaults to automatic
  63. sizing)}
  64. \item{height}{Width/Height in pixels (optional, defaults to automatic
  65. sizing)}
  66. \item{elementId}{An id for the widget (a random string by default).}
  67. \item{fillContainer}{\code{TRUE} to configure the table to automatically fill
  68. it's containing element. If the table can't fit fully into it's container
  69. then vertical and/or horizontal scrolling of the table cells will occur.}
  70. \item{autoHideNavigation}{\code{TRUE} to automatically hide navigational UI
  71. when the number of total records is less than the page size.}
  72. \item{selection}{the row/column selection mode (single or multiple selection
  73. or disable selection) when a table widget is rendered in a Shiny app;
  74. alternatively, you can use a list of the form \code{list(mode = 'multiple',
  75. selected = c(1, 3, 8), target = 'row')} to pre-select rows; the element
  76. \code{target} in the list can be \code{'column'} to enable column
  77. selection, or \code{'row+column'} to make it possible to select both rows
  78. and columns (click on the footer to select columns), or \code{'cell'} to
  79. select cells}
  80. \item{extensions}{a character vector of the names of the DataTables
  81. extensions (\url{https://datatables.net/extensions/index})}
  82. \item{plugins}{a character vector of the names of DataTables plug-ins
  83. (\url{https://rstudio.github.io/DT/plugins.html}). Note that only those
  84. plugins supported by the \code{DT} package can be used here.}
  85. \item{rownames}{\code{TRUE} (show row names) or \code{FALSE} (hide row names)
  86. or a character vector of row names; by default, the row names are displayed
  87. in the first column of the table if exist (not \code{NULL})}
  88. \item{digits}{the desired number of digits after the decimal
  89. point (\code{format = "f"}) or \emph{significant} digits
  90. (\code{format = "g"}, \code{= "e"} or \code{= "fg"}).
  91. Default: 2 for integer, 4 for real numbers. If less than 0,
  92. the C default of 6 digits is used. If specified as more than 50, 50
  93. will be used with a warning unless \code{format = "f"} where it is
  94. limited to typically 324. (Not more than 15--21 digits need be
  95. accurate, depending on the OS and compiler used. This limit is
  96. just a precaution against segfaults in the underlying C runtime.)
  97. }
  98. }
  99. \description{
  100. This function creates an HTML widget to display rectangular data (a matrix or data frame) using the JavaScript library DataTables, with a method for \code{desctable} objects.
  101. }
  102. \note{
  103. You are recommended to escape the table content for security reasons (e.g. XSS attacks) when using this function in Shiny or any other dynamic web applications.
  104. }
  105. \examples{
  106. library(DT)
  107. # see the package vignette for examples and the link to website
  108. vignette('DT', package = 'DT')
  109. # some boring edge cases for testing purposes
  110. m = matrix(nrow = 0, ncol = 5, dimnames = list(NULL, letters[1:5]))
  111. datatable(m) # zero rows
  112. datatable(as.data.frame(m))
  113. m = matrix(1, dimnames = list(NULL, 'a'))
  114. datatable(m) # one row and one column
  115. datatable(as.data.frame(m))
  116. m = data.frame(a = 1, b = 2, c = 3)
  117. datatable(m)
  118. datatable(as.matrix(m))
  119. # dates
  120. datatable(data.frame(
  121. date = seq(as.Date("2015-01-01"), by = "day", length.out = 5), x = 1:5
  122. ))
  123. datatable(data.frame(x = Sys.Date()))
  124. datatable(data.frame(x = Sys.time()))
  125. ###
  126. }
  127. \references{
  128. See \url{http://rstudio.github.io/DT} for the full documentation.
  129. }