Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set datanames #824

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
9d52672
Add datasets_selected argument
llrs-roche Jan 8, 2025
4cab9d5
Use datasets_selected for datanames
llrs-roche Jan 8, 2025
01af1e5
Add datasets_selected
llrs-roche Jan 8, 2025
7d1d1e9
Improve checks on datasets_selected
llrs-roche Jan 8, 2025
f64f3a0
Rstudio new version adds an id
llrs-roche Jan 8, 2025
f23555d
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 8, 2025
766a3c6
Rename argument
llrs-roche Jan 9, 2025
b782def
Rename datasets_selected to datanames
llrs-roche Jan 10, 2025
18791db
Deprecate show_metadata and use datanames
llrs-roche Jan 10, 2025
4a3682c
Update vignette
llrs-roche Jan 10, 2025
02e0408
Add tests checking deprecated arguments
llrs-roche Jan 10, 2025
441d069
Add NEWS entry
llrs-roche Jan 10, 2025
677075f
Correct example
llrs-roche Jan 10, 2025
24537f3
Style the R files
llrs-roche Jan 10, 2025
0bbce3a
Remove trailing commas
llrs-roche Jan 10, 2025
2708f8f
Merge branch 'main' into 821_select_datanames@main
llrs-roche Jan 10, 2025
fc4174e
Merge commit '268a6040c2143cd8e440a386b8334e2a41f008ce'
llrs-roche Jan 10, 2025
e2ebc56
Merge branch '821_select_datanames@main' of https://github.com/insigh…
llrs-roche Jan 10, 2025
af4143a
Apply suggestions from code review
llrs-roche Jan 10, 2025
0f8eae8
Fix superlinter issue (line > 120 character)
llrs-roche Jan 10, 2025
3b70824
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 10, 2025
341e039
Merge branch '821_select_datanames@main' of https://github.com/insigh…
llrs-roche Jan 10, 2025
883d667
Soft deprecate & use datasets_selected argument when possible
llrs-roche Jan 10, 2025
e6e5d10
Comment I missed when updating
llrs-roche Jan 10, 2025
6ba1998
Use full name of the function to avoid spelling false positives (and …
llrs-roche Jan 10, 2025
bd44f70
Prevent breaking user code and simplify code
llrs-roche Jan 10, 2025
111d2e5
[skip style] [skip vbump] Restyle files
github-actions[bot] Jan 10, 2025
59401be
Apply suggestions from code review
llrs-roche Jan 10, 2025
1493152
[skip style] [skip vbump] Restyle files
github-actions[bot] Jan 10, 2025
f108aa4
Keep the same default as before the PR and check if it is used before…
llrs-roche Jan 10, 2025
a591612
Remove unnecessary call
llrs-roche Jan 10, 2025
d79fee8
Add back the button control with datanames
llrs-roche Jan 10, 2025
60f9544
The default matches before this PR
llrs-roche Jan 10, 2025
1a40f0f
Styler changes
llrs-roche Jan 10, 2025
bd25c85
Update NEWS according to changes and discussion
llrs-roche Jan 10, 2025
1d1c716
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 10, 2025
478f9c9
Merge branch '821_select_datanames@main' of https://github.com/insigh…
llrs-roche Jan 10, 2025
e115f24
Use "all" instead of c("all", parent_dataname)
llrs-roche Jan 13, 2025
4e7265a
Convert check to one line
llrs-roche Jan 13, 2025
cb72e2a
Add lifecycle as a dependency
llrs-roche Jan 13, 2025
e5e29e0
Use deprecated() and missing
llrs-roche Jan 13, 2025
5fcca60
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 13, 2025
6faefc9
Use NULL as character0 is not accepted by teal::module(datanames)
llrs-roche Jan 14, 2025
9d85b7f
Merge branch '821_select_datanames@main' of https://github.com/insigh…
llrs-roche Jan 14, 2025
3c4ddb5
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 14, 2025
1a691ae
Add warning check (uncommited by error on last PR)
llrs-roche Jan 14, 2025
201576e
Merge branch '821_select_datanames@main' of https://github.com/insigh…
llrs-roche Jan 14, 2025
d7fe392
Import and no reassign
llrs-roche Jan 14, 2025
2da5d0b
Remove unnecessary NEWS entry
llrs-roche Jan 14, 2025
ba2b037
Shorter datasets_selected argument and remove the datanames' argument…
llrs-roche Jan 14, 2025
53ac5be
Use identical instead of !=
llrs-roche Jan 14, 2025
6f08e3d
Correct typo, shorten datases_selected argument's description, remove…
llrs-roche Jan 14, 2025
cc70989
Update documentation with feedback and typos corrected
llrs-roche Jan 14, 2025
7bd66d5
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 14, 2025
8545235
Update R/tm_variable_browser.R
llrs-roche Jan 14, 2025
c157c80
Remove tests
llrs-roche Jan 14, 2025
24db467
Merge branch 'main' into 821_select_datanames@main
llrs-roche Jan 15, 2025
4b2eba2
Set parent_dataname that matches data available
llrs-roche Jan 16, 2025
d28c934
Documentation update
llrs-roche Jan 16, 2025
2966292
[skip style] [skip vbump] Restyle files
github-actions[bot] Jan 16, 2025
999bdbd
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 16, 2025
cdfe6f7
Keep order or datanames
llrs-roche Jan 17, 2025
4f8e966
Merge branch '821_select_datanames@main' of https://github.com/insigh…
llrs-roche Jan 17, 2025
25d872e
Merge branch 'main' into 821_select_datanames@main
llrs-roche Jan 17, 2025
7485958
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 17, 2025
a561700
Fix broken merge
llrs-roche Jan 17, 2025
0deb55e
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Imports:
htmlwidgets (>= 1.6.4),
jsonlite (>= 1.8.9),
lattice (>= 0.18-4),
lifecycle (>= 0.2.0),
MASS (>= 7.3-61),
rlistings (>= 0.2.8),
rtables (>= 0.6.8),
Expand All @@ -69,7 +70,6 @@ Imports:
utils
Suggests:
knitr (>= 1.42),
lifecycle (>= 0.2.0),
logger (>= 0.2.0),
nestcolor (>= 0.1.0),
pkgload,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ import(shiny)
import(teal)
import(teal.transform)
importFrom(dplyr,"%>%")
importFrom(lifecycle,deprecated)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# teal.modules.general 0.3.0.9064

* Removed `Show Warnings` modals from modules.
* Soft deprecated `datasets_selected` argument of modules in favor of `datanames`.
* Soft deprecated `show_metadata` argument of `tm_front_page()` in favor of `datanames`.

### Enhancements

* Added `teal.logger` functionality for logging changes in shiny inputs in all modules.

### Bug fixes
Expand Down
32 changes: 16 additions & 16 deletions R/tm_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
#' Names of list elements should correspond to the names of the datasets available in the app.
#' If no entry is specified for a dataset, the first six variables from that
#' dataset will initially be shown.
#' @param datasets_selected (`character`) A vector of datasets which should be
#' shown and in what order. Names in the vector have to correspond with datasets names.
#' If vector of `length == 0` (default) then all datasets are shown.
#' Note: Only datasets of the `data.frame` class are compatible.
#' @param datasets_selected (`character`) `r lifecycle::badge("deprecated")` A vector of datasets which should be
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
#' shown and in what order. Use `datanames` instead.
#' @param dt_args (`named list`) Additional arguments to be passed to [DT::datatable()]
#' (must not include `data` or `options`).
#' @param dt_options (`named list`) The `options` argument to `DT::datatable`. By default
Expand Down Expand Up @@ -86,7 +84,8 @@
#'
tm_data_table <- function(label = "Data Table",
variables_selected = list(),
datasets_selected = character(0),
datasets_selected = deprecated(),
datanames = if (missing(datasets_selected)) "all" else datasets_selected,
dt_args = list(),
dt_options = list(
searching = FALSE,
Expand All @@ -111,8 +110,15 @@ tm_data_table <- function(label = "Data Table",
}
})
}

checkmate::assert_character(datasets_selected, min.len = 0, min.chars = 1)
if (!missing(datasets_selected)) {
lifecycle::deprecate_soft(
when = "0.4.0",
what = "tm_data_table(datasets_selected)",
with = "tm_data_table(datanames)",
details = 'Use tm_data_table(datanames = "all") to keep the previous behavior and avoid this warning.',
)
}
checkmate::assert_character(datanames, min.len = 0, min.chars = 1, null.ok = TRUE)
checkmate::assert(
checkmate::check_list(dt_args, len = 0),
checkmate::check_subset(names(dt_args), choices = names(formals(DT::datatable)))
Expand All @@ -128,10 +134,10 @@ tm_data_table <- function(label = "Data Table",
label,
server = srv_page_data_table,
ui = ui_page_data_table,
datanames = if (length(datasets_selected) == 0) "all" else datasets_selected,
datanames = datanames,
server_args = list(
datanames = datanames,
variables_selected = variables_selected,
datasets_selected = datasets_selected,
dt_args = dt_args,
dt_options = dt_options,
server_rendering = server_rendering
Expand Down Expand Up @@ -180,7 +186,7 @@ ui_page_data_table <- function(id, pre_output = NULL, post_output = NULL) {
# Server page module
srv_page_data_table <- function(id,
data,
datasets_selected,
datanames,
variables_selected,
dt_args,
dt_options,
Expand All @@ -193,16 +199,10 @@ srv_page_data_table <- function(id,
if_filtered <- reactive(as.logical(input$if_filtered))
if_distinct <- reactive(as.logical(input$if_distinct))

datanames <- isolate(names(data()))
datanames <- Filter(function(name) {
is.data.frame(isolate(data())[[name]])
}, datanames)

if (!identical(datasets_selected, character(0))) {
checkmate::assert_subset(datasets_selected, datanames)
datanames <- datasets_selected
}

output$dataset_table <- renderUI({
do.call(
tabsetPanel,
Expand Down
38 changes: 26 additions & 12 deletions R/tm_front_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#' `HTML("html text here")`.
#' @param footnotes (`character` vector) of text to be shown at the bottom of the module, for each
#' element, if named the name is shown first in bold, followed by the value.
#' @param show_metadata (`logical`) indicating whether the metadata of the datasets be available on the module.
#' @param show_metadata (`logical`) `r lifecycle::badge("deprecated")` indicating
#' whether the metadata of the datasets be available on the module.
#' Metadata shown automatically when `datanames` set.
#' @inheritParams tm_variable_browser
#'
#' @inherit shared_params return
#'
Expand Down Expand Up @@ -50,12 +53,11 @@
#' ),
#' tables = table_input,
#' additional_tags = HTML("Additional HTML or shiny tags go here <br>"),
#' footnotes = c("X" = "is the first footnote", "Y is the second footnote"),
#' show_metadata = TRUE
#' footnotes = c("X" = "is the first footnote", "Y is the second footnote")
#' )
#' ),
#' header = tags$h1("Sample Application"),
#' footer = tags$p("Application footer"),
#' footer = tags$p("Application footer")
#' )
#'
#' if (interactive()) {
Expand All @@ -69,7 +71,8 @@ tm_front_page <- function(label = "Front page",
tables = list(),
additional_tags = tagList(),
footnotes = character(0),
show_metadata = FALSE) {
show_metadata = deprecated(),
datanames = if (missing(show_metadata)) "all" else NULL) {
message("Initializing tm_front_page")

# Start of assertions
Expand All @@ -78,7 +81,19 @@ tm_front_page <- function(label = "Front page",
checkmate::assert_list(tables, types = "data.frame", names = "named", any.missing = FALSE)
checkmate::assert_multi_class(additional_tags, classes = c("shiny.tag.list", "html"))
checkmate::assert_character(footnotes, min.len = 0, any.missing = FALSE)
checkmate::assert_flag(show_metadata)
if (!missing(show_metadata)) {
lifecycle::deprecate_soft(
when = "0.4.0",
what = "tm_front_page(show_metadata)",
with = "tm_front_page(datanames)",
details = c(
"With `datanames` you can select which datasets are displayed.",
i = "Use `tm_front_page(datanames = 'all')` to keep the previous behavior and avoid this warning."
)
)
}
checkmate::assert_character(datanames, min.len = 0, min.chars = 1, null.ok = TRUE)

# End of assertions

# Make UI args
Expand All @@ -89,8 +104,8 @@ tm_front_page <- function(label = "Front page",
server = srv_front_page,
ui = ui_front_page,
ui_args = args,
server_args = list(tables = tables, show_metadata = show_metadata),
datanames = if (show_metadata) "all" else NULL
server_args = list(tables = tables),
datanames = datanames
)
attr(ans, "teal_bookmarkable") <- TRUE
ans
Expand Down Expand Up @@ -120,7 +135,7 @@ ui_front_page <- function(id, ...) {
class = "my-4",
args$additional_tags
),
if (args$show_metadata) {
if (length(args$datanames) > 0L) {
tags$div(
id = "front_page_metabutton",
class = "m-4",
Expand All @@ -136,7 +151,7 @@ ui_front_page <- function(id, ...) {
}

# Server function for the front page module
srv_front_page <- function(id, data, tables, show_metadata) {
srv_front_page <- function(id, data, tables) {
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
Expand All @@ -154,8 +169,7 @@ srv_front_page <- function(id, data, tables, show_metadata) {
caption.placement = "top"
)
})

if (show_metadata) {
if (length(isolate(names(data()))) > 0L) {
observeEvent(
input$metadata_button, showModal(
modalDialog(
Expand Down
6 changes: 4 additions & 2 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#' app <- init(
#' data = data,
#' modules = modules(
#' tm_missing_data()
#' tm_missing_data(parent_dataname = "mtcars")
#' )
#' )
#' if (interactive()) {
Expand Down Expand Up @@ -109,6 +109,7 @@
tm_missing_data <- function(label = "Missing data",
plot_height = c(600, 400, 5000),
plot_width = NULL,
datanames = "all",
parent_dataname = "ADSL",
ggtheme = c("classic", "gray", "bw", "linedraw", "light", "dark", "minimal", "void"),
ggplot2_args = list(
Expand All @@ -134,6 +135,7 @@ tm_missing_data <- function(label = "Missing data",
lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width"
)

checkmate::assert_character(datanames, min.len = 0, min.chars = 1, null.ok = TRUE)
checkmate::assert_character(parent_dataname, min.len = 0, max.len = 1)
ggtheme <- match.arg(ggtheme)

Expand All @@ -152,6 +154,7 @@ tm_missing_data <- function(label = "Missing data",
ans <- module(
label,
server = srv_page_missing_data,
datanames = if (identical(datanames, "all")) union(datanames, parent_dataname) else "all",
server_args = list(
parent_dataname = parent_dataname,
plot_height = plot_height,
Expand All @@ -161,7 +164,6 @@ tm_missing_data <- function(label = "Missing data",
decorators = decorators
),
ui = ui_page_missing_data,
datanames = "all",
ui_args = list(pre_output = pre_output, post_output = post_output)
)
attr(ans, "teal_bookmarkable") <- TRUE
Expand Down
44 changes: 25 additions & 19 deletions R/tm_variable_browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#' @inheritParams teal::module
#' @inheritParams shared_params
#' @param parent_dataname (`character(1)`) string specifying a parent dataset.
#' If it exists in `datasets_selected`then an extra checkbox will be shown to
#' If it exists in `datanames` then an extra checkbox will be shown to
#' allow users to not show variables in other datasets which exist in this `dataname`.
#' This is typically used to remove `ADSL` columns in `CDISC` data.
#' In non `CDISC` data this can be ignored. Defaults to `"ADSL"`.
#' @param datasets_selected (`character`) vector of datasets which should be
#' shown, in order. Names must correspond with datasets names.
#' If vector of length zero (default) then all datasets are shown.
#' Note: Only `data.frame` objects are compatible; using other types will cause an error.
#' @param datasets_selected (`character`) `r lifecycle::badge("deprecated")` vector of datasets to show, please
#' use the `datanames` argument.
#'
#' @inherit shared_params return
#'
Expand Down Expand Up @@ -81,7 +79,8 @@
#' @export
#'
tm_variable_browser <- function(label = "Variable Browser",
datasets_selected = character(0),
datasets_selected = deprecated(),
datanames = if (missing(datasets_selected)) "all" else datasets_selected,
parent_dataname = "ADSL",
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
pre_output = NULL,
post_output = NULL,
Expand All @@ -90,22 +89,37 @@ tm_variable_browser <- function(label = "Variable Browser",

# Start of assertions
checkmate::assert_string(label)
checkmate::assert_character(datasets_selected)
if (!missing(datasets_selected)) {
lifecycle::deprecate_soft(
when = "0.4.0",
what = "tm_variable_browser(datasets_selected)",
with = "tm_variable_browser(datanames)",
details = c(
"If both `datasets_selected` and `datanames` are set `datasets_selected` will be silently ignored.",
i = 'Use `tm_variable_browser(datanames = "all")` to keep the previous behavior and avoid this warning.'
)
)
}
checkmate::assert_character(datanames, min.len = 0, min.chars = 1, null.ok = TRUE)
checkmate::assert_character(parent_dataname, min.len = 0, max.len = 1)
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
checkmate::assert_class(ggplot2_args, "ggplot2_args")
# End of assertions

datasets_selected <- unique(datasets_selected)
datanames <- if (identical(datanames, "all")) {
"all"
} else {
union(datanames, parent_dataname)
}

ans <- module(
label,
server = srv_variable_browser,
ui = ui_variable_browser,
datanames = "all",
datanames = datanames,
server_args = list(
datasets_selected = datasets_selected,
datanames = datanames,
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
parent_dataname = parent_dataname,
ggplot2_args = ggplot2_args
),
Expand Down Expand Up @@ -194,7 +208,7 @@ srv_variable_browser <- function(id,
data,
reporter,
filter_panel_api,
datasets_selected, parent_dataname, ggplot2_args) {
datanames, parent_dataname, ggplot2_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
Expand All @@ -212,18 +226,10 @@ srv_variable_browser <- function(id,

varname_numeric_as_factor <- reactiveValues()

datanames <- isolate(names(data()))
datanames <- Filter(function(name) {
is.data.frame(isolate(data())[[name]])
}, datanames)

checkmate::assert_character(datasets_selected)
checkmate::assert_subset(datasets_selected, datanames)
if (!identical(datasets_selected, character(0))) {
checkmate::assert_subset(datasets_selected, datanames)
datanames <- datasets_selected
}

output$ui_variable_browser <- renderUI({
ns <- session$ns
do.call(
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
### global variables
ggplot_themes <- c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void")

#' @importFrom lifecycle deprecated
interactive <- NULL
18 changes: 13 additions & 5 deletions man/tm_data_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading