rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

ShinyDriver code inspection fails when using purrr-style functional notation #421

Open grddavies opened 2 years ago

grddavies commented 2 years ago

I'm wanting to use shinytest::ShinyDriver to test some interactive functionality in a module. When I try to instantiate the module, it fails on static code inspection, apparently bacause I'm using purrr-style function expressions in the module code.

A reprex (which is rather contrived and involves use of <<- but does accurately reproduce my error)

library(shiny)
mod_ui <- function(id) {
  ns <- NS(id)
  tagList(
    uiOutput(ns("btn1")),
    uiOutput(ns("btn2"))
  )
}

mod_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    ns <- session$ns
    purrr::walk(
      1:2,
      ~ {output[[paste0("btn", .)]] <<- renderUI(actionButton(ns(paste0("btn", .)), paste("btn", .)))}
    )
  })
}

app <- shinytest::ShinyDriver$new(shinyApp(mod_ui, mod_server))
#> Error in globalsByName(names, envir = envir, mustExist = mustExist): Identified global objects via static code inspection (function (id); {; moduleServer(id, function(input, output, session) {; ns <- session$ns; purrr::walk(1:2, ~{; output[[paste0("btn", .)]] <<- renderUI(actionButton(ns(paste0("btn",; .)), paste("btn", .))); }); }); }). Failed to locate global object in the relevant environments: '.'

Created on 2021-11-09 by the reprex package (v1.0.0)