【问题标题】:R Shiny, shinyapps.io printing error messages for R codesR Shiny,shinyapps.io 打印 R 代码的错误消息
【发布时间】:2022-01-18 02:41:49
【问题描述】:

我试图创建一个 Shiny 应用程序,它接受代码块并运行代码,然后给出该代码块的输出。

为此,我使用 textInput,然后尝试为用户提供输出。

Question1 <- reactive({
    eval(parse(text=input$Question1_code))
})

output$Question1_output <- renderText({
    input$Run_Code
    isolate(paste(Question1()))
})

现在,我的问题是当我在本地运行它时,我得到的输出是错误的语句/代码,例如

seq(1,10,-2)

'by' 参数中的登录错误。 (这是我希望看到的错误陈述)

但是,当我在 shinyapps.io 上运行它时,我收到以下错误消息,

发生错误。检查您的日志或联系应用作者进行澄清。

如何在shinyapps.io 上也打印我在本地收到的相同错误消息(“by”参数中的错误登录)?

【问题讨论】:

  • print the same error message on shinyapps.io 是什么意思?你想在 UI 上看到它吗?
  • @Iz100 实际上是的。我想在 UI 上打印错误/警告消息。当我在本地运行应用程序时可以显示错误消息,但我无法在我的网络应用程序上打印消息。
  • @OrcunOltulu Reagrding eval(parse(...,请务必阅读Mastering Shiny 中有关安全性的章节,尤其是:mastering-shiny.org/scaling-security.html#compute-resources
  • @markus 感谢您的反馈,我会查看该文档。

标签: r shiny eval


【解决方案1】:

spsComps使用shinyCatch

您的案例示例:

library(shiny)
library(spsComps)
ui <- fluidPage(
  actionButton("a", "blocking"),
  actionButton("b", "no blocking"),
)

server <- function(input, output, session) {
    observeEvent(input$a, {
      spsComps::shinyCatch({
          seq(1,10,-2)
      },
      # blocking recommended
      blocking_level = "error",
      prefix = "My-project" #change console prefix if you don't want "SPS"
      )
      # some other following actions will NOT  be run 
      print("other actions")
    })
    
    # if you dont want to block
    observeEvent(input$b, {
        spsComps::shinyCatch({
            seq(1,10,-2)
        }, prefix = "My-project")
        # some other following actions will run 
        print("other actions")
    })
}

shinyApp(ui, server)

或尝试更多演示here

【讨论】:

  • @Iz100 感谢您提供的示例代码。 shinyCatch() 似乎解决了我的问题
  • @OrcunOltulu 太好了,那么您可以考虑接受这篇文章作为最佳答案。
猜你喜欢
  • 2015-04-12
  • 2021-10-13
  • 2023-04-05
  • 1970-01-01
  • 2018-07-09
  • 2021-07-30
  • 1970-01-01
  • 2022-12-21
  • 1970-01-01
相关资源
最近更新 更多