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.

185 lines
7.1KB

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