|
1 | | -#' Data Table Viewer `teal` Module |
| 1 | +#' Data table viewer module |
2 | 2 | #' |
3 | | -#' A data table viewer shows the data using a paginated table. |
4 | | -#' specifically designed for use with `data.frames`. |
5 | | -#' @md |
| 3 | +#' Module provides a dynamic and interactive way to view `data.frame`s in a `teal` application. |
| 4 | +#' It uses the `DT` package to display data tables in a paginated, searchable, and sortable format, |
| 5 | +#' which helps to enhance data exploration and analysis. |
| 6 | +#' |
| 7 | +#' The `DT` package has an option `DT.TOJSON_ARGS` to show `Inf` and `NA` in data tables. |
| 8 | +#' Configure the `DT.TOJSON_ARGS` option via |
| 9 | +#' `options(DT.TOJSON_ARGS = list(na = "string"))` before running the module. |
| 10 | +#' Note though that sorting of numeric columns with `NA`/`Inf` will be lexicographic not numerical. |
6 | 11 | #' |
7 | 12 | #' @inheritParams teal::module |
8 | 13 | #' @inheritParams shared_params |
9 | | -#' @param variables_selected (`list`) A named list of character vectors of the variables (i.e. columns) |
10 | | -#' which should be initially shown for each dataset. Names of list elements should correspond to the names |
11 | | -#' of the datasets available in the app. If no entry is specified for a dataset, the first six variables from that |
12 | | -#' dataset will initially be shown. |
| 14 | +#' @param variables_selected (`named list`) Character vectors of the variables (i.e. columns) |
| 15 | +#' which should be initially shown for each dataset. |
| 16 | +#' Names of list elements should correspond to the names of the datasets available in the app. |
| 17 | +#' If no entry is specified for a dataset, the first six variables from that |
| 18 | +#' dataset will initially be shown. |
13 | 19 | #' @param datasets_selected (`character`) A vector of datasets which should be |
14 | | -#' shown and in what order. Names in the vector have to correspond with datasets names. |
15 | | -#' If vector of length zero (default) then all datasets are shown. |
16 | | -#' Note: Only datasets of the `data.frame` class are compatible; |
17 | | -#' using other types will cause an error. |
18 | | -#' @param dt_args (named `list`) Additional arguments to be passed to `DT::datatable` |
19 | | -#' (must not include `data` or `options`). |
20 | | -#' @param dt_options (named `list`) The `options` argument to `DT::datatable`. By default |
21 | | -#' `list(searching = FALSE, pageLength = 30, lengthMenu = c(5, 15, 30, 100), scrollX = TRUE)` |
| 20 | +#' shown and in what order. Names in the vector have to correspond with datasets names. |
| 21 | +#' If vector of `length == 0` (default) then all datasets are shown. |
| 22 | +#' Note: Only datasets of the `data.frame` class are compatible. |
| 23 | +#' @param dt_args (`named list`) Additional arguments to be passed to [DT::datatable()] |
| 24 | +#' (must not include `data` or `options`). |
| 25 | +#' @param dt_options (`named list`) The `options` argument to `DT::datatable`. By default |
| 26 | +#' `list(searching = FALSE, pageLength = 30, lengthMenu = c(5, 15, 30, 100), scrollX = TRUE)` |
22 | 27 | #' @param server_rendering (`logical`) should the data table be rendered server side |
23 | | -#' (see `server` argument of `DT::renderDataTable()`) |
24 | | -#' @details |
25 | | -#' The `DT` package has an option `DT.TOJSON_ARGS` to show `Inf` and `NA` in data tables. If this is something |
26 | | -#' you require then set `options(DT.TOJSON_ARGS = list(na = "string"))` before running the module. |
27 | | -#' Note though that sorting of numeric columns with `NA`/`Inf` will be lexicographic not numerical. |
| 28 | +#' (see `server` argument of [DT::renderDataTable()]) |
28 | 29 | #' |
29 | 30 | #' @examples |
30 | 31 | #' # general data example |
31 | | -#' |
32 | 32 | #' data <- teal_data() |
33 | 33 | #' data <- within(data, { |
34 | 34 | #' require(nestcolor) |
@@ -127,8 +127,7 @@ tm_data_table <- function(label = "Data Table", |
127 | 127 | ) |
128 | 128 | } |
129 | 129 |
|
130 | | - |
131 | | -# ui page module |
| 130 | +# UI page module |
132 | 131 | ui_page_data_table <- function(id, |
133 | 132 | pre_output = NULL, |
134 | 133 | post_output = NULL) { |
@@ -162,8 +161,7 @@ ui_page_data_table <- function(id, |
162 | 161 | ) |
163 | 162 | } |
164 | 163 |
|
165 | | - |
166 | | -# server page module |
| 164 | +# Server page module |
167 | 165 | srv_page_data_table <- function(id, |
168 | 166 | data, |
169 | 167 | datasets_selected, |
@@ -247,6 +245,7 @@ srv_page_data_table <- function(id, |
247 | 245 | }) |
248 | 246 | } |
249 | 247 |
|
| 248 | +# UI function for the data_table module |
250 | 249 | ui_data_table <- function(id, |
251 | 250 | choices, |
252 | 251 | selected) { |
@@ -276,6 +275,7 @@ ui_data_table <- function(id, |
276 | 275 | ) |
277 | 276 | } |
278 | 277 |
|
| 278 | +# Server function for the data_table module |
279 | 279 | srv_data_table <- function(id, |
280 | 280 | data, |
281 | 281 | dataname, |
|
0 commit comments