我有一个shiny应用程序,每天晚上通过rsconnect::deployApp使用批处理文件和预定任务进行更新。此过程目前正在按预期运行,但目前确认整个过程成功的唯一方法是访问应用程序并检查时间戳是否被更新。
?deployApp显示了一个on.failure选项,它将在部署失败时调用一个函数。如果部署失败,我想知道如何使用它发送通知,但是我无法测试它,因为我实际上不能使deployApp函数失败。
我尝试过在UI中放置错误,但是应用程序成功地部署了,尽管在查看器和shinyapps.io上没有功能。
有没有办法强迫deployApp函数失败,这样我就能够测试我正在创建的on.failure函数?
如果需要的话,这里有一个从这里借来的闪亮的小应用程序。
# Global variables can go here
n <- 200
# Define the UI
ui <- bootstrapPage(
numericInput('n', 'Number of obs', n),
plotOutput('plot')
)
# Define the server code
server <- function(input, output) {
output$plot <- renderPlot({
hist(runif(input$n))
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)目前运行R v. 4.0.2;rsconnect 0.8.16,闪亮1.5.0
编辑:我试着把一个q()偷偷溜进应用程序。它肯定会破坏应用程序,但不会干扰deployApp。搜索还在继续!
发布于 2020-10-08 16:31:40
我的猜测是,当部署中出现错误时,on.failure会触发。从这个角度来看,代码中的错误(stop甚至q)只在它篡改部署时触发on.failure。由于在deployApp中没有对代码本身进行明显的检查,所以它可能不会像这样工作。
查看底层rsconnect:::openURL (其中使用了on.failure参数),我们看到on.failure在两个条件下使用:
if (!is.null(client$configureApplication)) {
config <- client$configureApplication(application$id)
url <- config$config_url
if (!deploymentSucceeded && validURL(config$logs_url)) {
url <- config$logs_url
}
if (validURL(url)) {
if (deploymentSucceeded) {
showURL(url)
}
else if (is.function(on.failure)) {
on.failure(url) ## here
}
}
}
else if (deploymentSucceeded) {
showURL(application$url)
}
else if (is.function(on.failure)) {
on.failure(NULL) ## and here
}因此,我要测试的是debug(rsconnect:::openURL),当浏览器打开时,我只需设置client$configureApplication <- NULL;deploymentSucceeded <- FALSE并继续代码。
然而,看看代码,我们看到了所有将要发生的事情就是,on.failure被调用了。因此,直接调用on.failure将产生同样的效果。
https://stackoverflow.com/questions/64249503
复制相似问题