Skip to content

[Bug]: tm_a_pca doesn't work with delayed data extract specs #715

@averissimo

Description

@averissimo

What happened?

Problem

Example of tm_a_pca using a character name for the dataset to extract the data does not behave the same and produces an error.

When inspecting the code, response[[i]] variable processing assumes that it's not a delayed_data object.

response[[i]]$select$multiple <- FALSE
response[[i]]$select$always_selected <- NULL
response[[i]]$select$selected <- NULL
all_cols <- teal.data::col_labels(isolate(data())[[response[[i]]$dataname]])
ignore_cols <- unlist(teal.data::join_keys(isolate(data()))[[response[[i]]$dataname]])
color_cols <- all_cols[!names(all_cols) %in% ignore_cols]
response[[i]]$select$choices <- choices_labeled(names(color_cols), color_cols)

How to reproduce:

library(teal.module.general)

data <- within(teal_data(), {
  require(nestcolor)
  USArrests <- USArrests
})
datanames(data) <- "USArrests"

## Delayed data (with error)
teal::init(
  data = data,
  modules = teal.module.general::tm_a_pca(
    dat = teal.transform::data_extract_spec(
      dataname = "USArrests",
      select = select_spec(
        choices = teal.transform::variable_choices(
          data = "USArrests",
          c("Murder", "Assault", "UrbanPop", "Rape")
        ),
        selected = c("Murder", "Assault"),
        multiple = TRUE
      )
    )
  )
) |> shiny::runApp()

image

Expected behavior

Same result using example for module (that uses variable_choices with data itself instead of character)

# Non-delayed data (without error)
teal::init(
  data = data,
  modules = tm_a_pca(
    dat = data_extract_spec(
      dataname = "USArrests",
      select = select_spec(
        choices = variable_choices(
          data = data[["USArrests"]],
          c("Murder", "Assault", "UrbanPop", "Rape")
        ),
        selected = c("Murder", "Assault"),
        multiple = TRUE
      )
    )
  )
) |> shiny::runApp()

sessionInfo()

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions