teal icon indicating copy to clipboard operation
teal copied to clipboard

[Bug]: `datanames` code and environment don't match under edge case

Open averissimo opened this issue 1 year ago • 0 comments

What happened?

Possible Edge case:

  • App developer uses object in pre-processing
    • Such as a function
  • datanames ≠ "all" (is NOT set to all)
  • 🔴 Data passed to module has discrepancy in code / "content of qenv"
    • pre-processing objects used to generate datanames are not included

In the sample app (code below) we can observe this when comparing ls(data(), all.names = TRUE) and get_code(data())

note: cbind is also not store in .raw_data

image

Sample App code

pkgload::load_all("teal")
library(teal)
data <- teal_data() |>
  within({
    iris <- iris
    mtcars <- mtcars
    new_column <- data.frame(what = "new_column")
    cbind2 <- function(lhs, rhs) cbind(lhs, rhs)
    iris <- cbind2(iris, data.frame(new_column))
  })

app <- init(
  data = data,
  modules = module(
    ui = function(id) {
      shiny::tagList(
        shiny::tags$h3("Code in module"),
        shiny::verbatimTextOutput(shiny::NS(id, "code")),
        shiny::tags$h3("Contents of data() in module"),
        shiny::verbatimTextOutput(shiny::NS(id, "contents")),
        
        example_module()$ui(id)
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        output$contents <- renderText({
          paste(
            "Available variables in the qenv env:",
            paste(ls(teal.code::get_env(data()), all.names = TRUE), collapse = ", ")
          )
        })
        output$code <- renderText({
          teal.code::get_code(data()) |> paste(collapse = "\n")
        })
      })
      example_module()$server(id, data)
    },
    datanames = "iris"
  )
)

shiny::runApp(app)

sessionInfo()

No response

Relevant log output

No response

Code of Conduct

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

Contribution Guidelines

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

Security Policy

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

averissimo avatar Oct 21 '24 11:10 averissimo