R 如何使用shinytest记录或跟踪?

R 如何使用shinytest记录或跟踪?,r,shiny,rstudio,R,Shiny,Rstudio,我希望能够看到代码中的反应({…})部分内部发生了什么。我认为使用shinytest可以执行我的应用程序中使用闪亮模块的部分,并了解调用模块 我在代码中尝试了以下方法来记录/跟踪/打印 print("hello1") message("hello2") cat(file=stderr(), "hello3") logging::loginfo("hello4") runtest.R library(shinytest) testApp("/home/eddy/rwork/filters", "

我希望能够看到代码中的
反应({…})
部分内部发生了什么。我认为使用shinytest可以执行我的应用程序中使用
闪亮模块
的部分,并了解
调用模块

我在代码中尝试了以下方法来记录/跟踪/打印

print("hello1")
message("hello2")
cat(file=stderr(), "hello3")
logging::loginfo("hello4")
runtest.R

library(shinytest)
testApp("/home/eddy/rwork/filters", "mytest")
viewTestDiff("/home/eddy/rwork/filters", interactive = FALSE)
输出:

Rscript runtest.R
Running mytest.R 
==== Comparing mytest... No changes.
==== mytest ====
No differences between expected and current results
如何向测试运行添加一些跟踪输出?

您可以在反应式函数中添加一个print()、cat()、warning(),以在R提示符中检查对象的值o类。这适用于我在RStudio中只使用Shinny而不使用shinytest的情况。 另外,正如您所说,它不适用于前面的选项,您可以放置一个
write.myformat()
函数,以便写入任何类型的对象并在外部进行检查。

您可以在响应函数中添加一个print()、cat()、warning(),以在R提示符中检查对象的类值。这适用于我在RStudio中只使用Shinny而不使用shinytest的情况。
此外,正如您所说,前面的选项不起作用,您可以放置一个
write.myformat()
函数,以便编写任何类型的对象并在外部检查它。

我认为现在没有一种真正方便的方法在shinytest中查看应用程序输出,但ShinyDriver对象上有以下方法:

app$getDebugLog()
查询一个或多个调试日志:
shiny_控制台
浏览器
shinytest

您可以将其与
shinny_控制台
选项一起使用,以便在单独的测试中打印应用程序输出,如:

# mytest.R

app <- ShinyDriver$new()

...

log <- app$getDebugLog("shiny_console")
print(log)
#mytest.R

app我认为现在没有一种非常方便的方法可以在shinytest中查看app输出,但是在ShinyDriver对象上有一种方法:

app$getDebugLog()
查询一个或多个调试日志:
shiny_控制台
浏览器
shinytest

您可以将其与
shinny_控制台
选项一起使用,以便在单独的测试中打印应用程序输出,如:

# mytest.R

app <- ShinyDriver$new()

...

log <- app$getDebugLog("shiny_console")
print(log)
#mytest.R

appshinytest在测试过程中集成了导出值的shinny概念,因此您可以使用该函数创建包含要导出的值(包括反应值)的命名表达式

例如,如果您有reactive data.frame,
scaleData
,它在应用程序代码中使用了某种类型的输入绑定,那么您可以执行以下操作:

scaledData <- reactive({
  dummyData[, "y"] <- dummyData[, "y"] * input$scale
  return(dummyData)
})

# The scaledData will be captured as a json object in the shinytest output
exportTestValues(scaledData = scaledData())

scaleDatashinytest在测试过程中集成了导出值的shinny概念,因此您可以使用该函数创建包含要导出的值(包括反应值)的命名表达式

例如,如果您有reactive data.frame,
scaleData
,它在应用程序代码中使用了某种类型的输入绑定,那么您可以执行以下操作:

scaledData <- reactive({
  dummyData[, "y"] <- dummyData[, "y"] * input$scale
  return(dummyData)
})

# The scaledData will be captured as a json object in the shinytest output
exportTestValues(scaledData = scaledData())
scaledData