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 6 commits into
base: main
Choose a base branch
from
Open

Conversation

llrs-roche
Copy link
Contributor

@llrs-roche llrs-roche commented Jan 8, 2025

Pull Request

Fixes #821

This PR add a parameter (or uses existing ones) to use on teal::module(datanames) to select which datasets are shown in each module.

tm_file_viewer() doesn't have and I think shouldn't have.

Acceptance criteria:

tm_missing_data example
# general example data

library("devtools")
load_all("../teal.modules.general")
load_all("../teal.code")
load_all("../teal.transform")
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  
  add_nas <- function(x) {
    x[sample(seq_along(x), floor(length(x) * runif(1, .05, .17)))] <- NA
    x
  }
  
  iris <- iris
  .iris <- iris
  iris2 <- iris
  mtcars <- mtcars
  
  iris[] <- lapply(iris, add_nas)
  .iris[] <- lapply(.iris, add_nas)
  iris2[] <- lapply(iris2, add_nas)
  mtcars[] <- lapply(mtcars, add_nas)
  mtcars[["cyl"]] <- as.factor(mtcars[["cyl"]])
  mtcars[["gear"]] <- as.factor(mtcars[["gear"]])
})

app <- init(
  data = data,
  modules = modules(
    tm_missing_data(datasets_selected = c("iris2", "iris"))
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}
tm_variable_browser example
library("devtools")
load_all("../teal.modules.general")
load_all("../teal.code")
load_all("../teal.transform")
# general data example
data <- teal_data()
data <- within(data, {
  iris <- iris
  mtcars <- mtcars
  women <- women
  faithful <- faithful
  CO2 <- CO2
})

app <- init(
  data = data,
  modules = modules(
    tm_variable_browser(
      label = "Variable browser",
      datasets_selected = c("iris", "mtcars")
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}
tm_front_page (additional modifications to enable granular selection): Example
library("devtools")
load_all("../teal.modules.general")
load_all("../teal.code")
load_all("../teal.transform")
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
  ADSL2 <- ADSL
  attr(ADSL, "metadata") <- list("Author" = "NEST team", "data_source" = "synthetic data")
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

table_1 <- data.frame(Info = c("A", "B"), Text = c("A", "B"))
table_2 <- data.frame(`Column 1` = c("C", "D"), `Column 2` = c(5.5, 6.6), `Column 3` = c("A", "B"))
table_3 <- data.frame(Info = c("E", "F"), Text = c("G", "H"))

table_input <- list(
  "Table 1" = table_1,
  "Table 2" = table_2,
  "Table 3" = table_3
)

app <- init(
  data = data,
  modules = modules(
    tm_front_page(
      header_text = c(
        "Important information" = "It can go here.",
        "Other information" = "Can go here."
      ),
      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,
      datasets_selected = "ADSL2"
    )
  ),
  header = tags$h1("Sample Application"),
  footer = tags$p("Application footer"),
)

if (interactive()) {
  shinyApp(app$ui, app$server)
}

I checked via searching datanames = that there are now at least 15 cases in module() corresponding to the 15 modules exported.
image

There is one that is not configurable (datanames = NULL on the picture above), tm_file_viewer. In my opinion it doesn't matter the datasets available on the module to visualize files. But if needed we can add a dataset_selected argument.

Note that I added the dataset_selected argument to two modules on the best place I thought, if a package/user is using positional arguments it might break (and also teal.gallery).

Note that it doesn't show on shinylive (on Rstudio, preview, not sure if once fully installed) and also that it doesn't show the url (this could be an issue with my machine):

tmg_tm_file_viewer_datanames

@llrs-roche llrs-roche added the core label Jan 8, 2025
Copy link
Contributor

github-actions bot commented Jan 8, 2025

Unit Tests Summary

  1 files   22 suites   13m 8s ⏱️
145 tests 107 ✅ 38 💤 0 ❌
476 runs  438 ✅ 38 💤 0 ❌

Results for commit f23555d.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
shinytest2-tm_a_pca 💔 $115.73$ $+2.77$ $0$ $0$ $0$ $0$
shinytest2-tm_front_page 💔 $20.34$ $+1.01$ $0$ $0$ $0$ $0$
shinytest2-tm_g_association 💔 $30.17$ $+1.60$ $0$ $0$ $0$ $0$
shinytest2-tm_g_bivariate 💔 $73.71$ $+1.29$ $0$ $0$ $0$ $0$
shinytest2-tm_g_scatterplot 💔 $72.89$ $+1.11$ $0$ $0$ $0$ $0$
shinytest2-tm_t_crosstable 💔 $31.18$ $+1.16$ $0$ $0$ $0$ $0$

Results for commit 101cc5c

♻️ This comment has been updated with latest results.

Comment on lines +90 to +96
datanames <- if (show_metadata && length(datasets_selected) > 0L) {
datasets_selected
} else if (show_metadata) {
"all"
} else {
NULL
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a gap here when show_metadata = FALSE and length(datasets_selected). This show_metadata argument is unnecessary and I would suggest to deprecate show_metadata and to show metadata when datasets_selected is not empty. So:

tm_front_page <- function(
  datasets_selected = NULL,
  show_metadata = <deprecated>
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On that condition show_metadata prevails and nothing would be shown... but I can deprecate show_metadata entirely.

@@ -110,6 +111,7 @@
tm_missing_data <- function(label = "Missing data",
plot_height = c(600, 400, 5000),
plot_width = NULL,
datasets_selected = character(0L),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this argument was named datanames it would be inherited from teal::module.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with what is used in other modules, currently there are 2 modules using this argument: tm_data_table and tm_variable_browser. Let me know if you want me to rename those other modules too.
I haven't tested what happens with transformators...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be much easier if tm_data_table and tm_variable_browser had datanames instead of datasets_selected . I wouldn't rename them, but:

  datanames = "all",
  datasets_selected = <deprecated>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do that and check what happens with transformators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to set datanames in module's constructor
2 participants