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.

195 lines
7.8KB

  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/deprecated.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 = list(), dom = "Brtip", fixedColumns =
  32. T, 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{https://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{https://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 by
  83. one when using \code{rownames}}
  84. \item{style}{either \code{'auto'}, \code{'default'}, \code{'bootstrap'}, or
  85. \code{'bootstrap4'}. If \code{'auto'}, and a **bslib** theme is
  86. currently active, then bootstrap styling is used in a way that "just works"
  87. for the active theme. Otherwise,
  88. \href{https://datatables.net/manual/styling/classes}{DataTables
  89. \code{'default'} styling} is used. If set explicitly to \code{'bootstrap'}
  90. or \code{'bootstrap4'}, one must take care to ensure Bootstrap's HTML
  91. dependencies (as well as Bootswatch themes, if desired) are included on the
  92. page. Note, when set explicitly, it's the user's responsibility to ensure
  93. that only one unique `style` value is used on the same page, if multiple
  94. DT tables exist, as different styling resources may conflict with each other.}
  95. \item{width}{Width/Height in pixels (optional, defaults to automatic
  96. sizing)}
  97. \item{height}{Width/Height in pixels (optional, defaults to automatic
  98. sizing)}
  99. \item{elementId}{An id for the widget (a random string by default).}
  100. \item{fillContainer}{\code{TRUE} to configure the table to automatically fill
  101. it's containing element. If the table can't fit fully into it's container
  102. then vertical and/or horizontal scrolling of the table cells will occur.}
  103. \item{autoHideNavigation}{\code{TRUE} to automatically hide navigational UI
  104. (only display the table body) when the number of total records is less
  105. than the page size. Note, it only works on the client-side processing mode
  106. and the `pageLength` option should be provided explicitly.}
  107. \item{selection}{the row/column selection mode (single or multiple selection
  108. or disable selection) when a table widget is rendered in a Shiny app;
  109. alternatively, you can use a list of the form \code{list(mode = 'multiple',
  110. selected = c(1, 3, 8), target = 'row', selectable = c(-2, -3))} to
  111. pre-select rows and control the selectable range; the element
  112. \code{target} in the list can be \code{'column'} to enable column
  113. selection, or \code{'row+column'} to make it possible to select both rows
  114. and columns (click on the footer to select columns), or \code{'cell'} to
  115. select cells. See details section for more info.}
  116. \item{extensions}{a character vector of the names of the DataTables
  117. extensions (\url{https://datatables.net/extensions/index})}
  118. \item{plugins}{a character vector of the names of DataTables plug-ins
  119. (\url{https://rstudio.github.io/DT/plugins.html}). Note that only those
  120. plugins supported by the \code{DT} package can be used here. You can see
  121. the available plugins by calling \code{DT:::available_plugins()}}
  122. \item{rownames}{\code{TRUE} (show row names) or \code{FALSE} (hide row names)
  123. or a character vector of row names; by default, the row names are displayed
  124. in the first column of the table if exist (not \code{NULL})}
  125. \item{digits}{the desired number of digits after the decimal
  126. point (\code{format = "f"}) or \emph{significant} digits
  127. (\code{format = "g"}, \code{= "e"} or \code{= "fg"}).
  128. Default: 2 for integer, 4 for real numbers. If less than 0,
  129. the C default of 6 digits is used. If specified as more than 50, 50
  130. will be used with a warning unless \code{format = "f"} where it is
  131. limited to typically 324. (Not more than 15--21 digits need be
  132. accurate, depending on the OS and compiler used. This limit is
  133. just a precaution against segfaults in the underlying C runtime.)
  134. }
  135. }
  136. \description{
  137. 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.
  138. }
  139. \note{
  140. 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.
  141. }
  142. \examples{
  143. library(DT)
  144. # see the package vignette for examples and the link to website
  145. vignette('DT', package = 'DT')
  146. # some boring edge cases for testing purposes
  147. m = matrix(nrow = 0, ncol = 5, dimnames = list(NULL, letters[1:5]))
  148. datatable(m) # zero rows
  149. datatable(as.data.frame(m))
  150. m = matrix(1, dimnames = list(NULL, 'a'))
  151. datatable(m) # one row and one column
  152. datatable(as.data.frame(m))
  153. m = data.frame(a = 1, b = 2, c = 3)
  154. datatable(m)
  155. datatable(as.matrix(m))
  156. # dates
  157. datatable(data.frame(
  158. date = seq(as.Date("2015-01-01"), by = "day", length.out = 5), x = 1:5
  159. ))
  160. datatable(data.frame(x = Sys.Date()))
  161. datatable(data.frame(x = Sys.time()))
  162. ###
  163. }
  164. \references{
  165. See \url{https://rstudio.github.io/DT/} for the full documentation.
  166. }
  167. \keyword{deprecated}