会话$ onSessionEnded中的Retreive错误消息

时间:2017-08-22 11:54:44

标签: shiny

在我的应用关闭之前,如果应用关闭有或没有错误,我想登录文件。

理想情况下,我想设置我的2个变量:

  • error为布尔值(错误与否)
  • errorMessage作为字符(错误消息)

我的例子:

library(shiny)

ui <- fluidPage(
      mainPanel(
         actionButton("works","Exit without error")
         ,actionButton("error","Exit with error")
      )
)

server <- function(session, input, output) {
    session$onSessionEnded(function() {
        # Herebelow my 2 variables I want to set dynamically :
        error = TRUE
        errorMessage =  "my error"
        if (error) {
          write(x = paste("App has temrinated with error :",errorMessage), file = "./myLogFile.txt", append = TRUE)
        } else {
          write(x = "App has terminated without error", file = "./myLogFile.txt", append = TRUE)
        }
    })

    observeEvent(input$works, {
      stopApp()
    })

    observeEvent(input$error, {
      function_that_doesnt_exist()
    })
}

shinyApp(ui = ui, server = server)

编辑:

当我设置options(shiny.error = browser)时,我得到变量e,这正是我正在寻找的(见下图)。 但是我无法在session$onSessionEnded

中获得它

enter image description here

0 个答案:

没有答案