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

Display output on tm_data_table, tm_variable_browser, tm_missing_data #829

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

llrs-roche
Copy link
Contributor

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

Pull Request

Fixes insightsengineering/teal#1452

This PR works on the edge cases of datanames = "all" and NULL for each three modules, in addition I also revised the decision on tm_front_page to show all modules by default, and reverted back to not showing the panels by default, as per previous behavior and @vedhav compelling comment.

Code used to check this (besides the examples)
library("teal")
devtools::load_all("../teal.modules.general")

data <- teal_data()
data <- within(data, {
  library(dplyr)
  IRIS <- iris
  MTCARS <- mtcars
  # ADSL <- teal.data::rADSL
})

datanames <- "all"

app <- init(
  data = data,
  modules = modules(
    example_module(),
    tm_front_page(datanames = datanames),
    tm_data_table(datanames = datanames),
    tm_variable_browser(datanames = datanames),
    tm_missing_data(datanames = datanames)
  )
)

shinyApp(app$ui, app$server)


datanames <- NULL

app <- init(
  data = data,
  modules = modules(
    example_module(),
    tm_front_page(datanames = datanames),
    tm_data_table(datanames = datanames),
    tm_variable_browser(datanames = datanames),
    tm_missing_data(datanames = datanames)
  )
)

shinyApp(app$ui, app$server)
module "all" NULL
tm_data_table() ✅ 1
tm_variable_browser() ✅ 2
tm_missing_data() ✅ 2

1: No right-panel but the table uses all datasets that are data.frames. I was thinking if variables_selected names should be used when datanames is NULL ? So that something like this should only show IRIS dataset and no left panel.

teal.modules.general::tm_data_table(datanames = NULL,
                                      variables_selected = list(IRIS = colnames(data$IRIS)[1:3])),

But this gets complicated if one wants to keep the standard 6 columns of the datasests as assertion fails:

teal.modules.general::tm_data_table(datanames = NULL,
                                      variables_selected = list(IRIS = colnames(data$IRIS)[1:3], MTCARS = NULL)),
Assertion on 'variables_selected' failed: May only contain the following types: {character}, but element 2 has type 'NULL'.

2: No right-panel but all the datasets that are data.frames are shown.


I also tested whether transformators worked with tm_missing_data (the only one of these three modules with a transformator argument) because the datanames documentation implies it will be merged with it: currently it doesn't and I'm not sure how to fix it.

If I create a transformator and use datanames not equal to all by default the new dataname won't be used.
I need to explore better the interaction between teal::module and the transformator.

reprex with transformator
library("teal")

data <- teal_data()
data <- within(data, {
  library(dplyr)
  IRIS <- iris
  MTCARS <- mtcars
  # ADSL <- teal.data::rADSL
})


transf <- list(teal_transform_module(
  label = "Transformator",
  ui = function(id) {
    ns <- NS(id)
    tags$div(
      numericInput(ns("n_rows"), "Number of rows to subset", value = 32, min = 1, max = 150, step = 1)
    )
  },
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      reactive({
        within(data(),
               {
                 iris <- head(IRIS, num_rows)
               },
               num_rows = input$n_rows
        )
      })
    })
  },
  datanames = "all"
))


datanames <- "IRIS"

app <- init(
  data = data,
  modules = modules(
    example_module(),
    tm_front_page(datanames = datanames),
    tm_data_table(datanames = datanames),
    tm_variable_browser(datanames = datanames),
    tm_missing_data(datanames = datanames, transformators = transf)
  )
)

shinyApp(app$ui, app$server)

@m7pr
Copy link
Contributor

m7pr commented Jan 22, 2025

@llrs-roche about transformators and datanames. Have you tried to unify names?
Looks like teal_data() only contains IRIS and MTCARS, however module uses only IRIS BUT your transformator tries to change iris

image

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.

[Bug]: missing_data, data_table and variable_browser are not displating output
2 participants