如何检测 'shinytest' 是 运行 闪亮的应用程序?

How to detect 'shinytest' is running a Shiny app?

我找到了 bug in 'shinytest' with 'rhandsontable' when using 'hot_validate_numeric'

简而言之,此代码会导致 'shinytest' 出现问题:

  output[["hot2"]] <- renderRHandsontable({
    rhandsontable(head(iris)) %>%
      hot_validate_numeric(col = 1, min = 0, max = 100) # <-- problem
  })

我想用 'shinytest' 测试我的应用程序,但我不想删除 hot_validate_numeric(col = 1, min = 0, max = 100)。那么有没有一种方法可以检测该应用程序是否由 'shinytest' 提供支持,以便执行以下操作:

if(shinytestIsRunning){
  output[["hot2"]] <- renderRHandsontable({
    rhandsontable(head(iris))
  })
}else{
  output[["hot2"]] <- renderRHandsontable({
    rhandsontable(head(iris)) %>%
      hot_validate_numeric(col = 1, min = 0, max = 100)
  })
}

我觉得我有办法

运行 'shinytest'如下:

library(shinytest)
app <- ShinyDriver$new(".", loadTimeout = 1e+05,
                       shinyOptions = list(test.mode = TRUE))

然后 getOption("shiny.testmode")TRUE 当 'shinytest' 是 运行 应用程序。