【问题标题】:Change the default error message in Shiny更改 Shiny 中的默认错误消息
【发布时间】:2021-04-21 21:32:06
【问题描述】:

目前我正在使用它来处理用户在我的应用中输入任何错误数据:

options(shiny.sanitize.errors = TRUE)

它返回此错误消息:

Error: An error has occurred. Check your logs or contact the app author for clarification.

有没有办法将此消息的内容更改为其他内容,例如说“无效的用户名。请重试”,我不想使用 try-catch,只想更改此默认错误消息。

【问题讨论】:

  • tryCatch()怎么样?
  • 没有办法改变它。我只会处理发生的错误。当发生其他意外错误时,类似的特定全局错误消息也可能使用户感到困惑。
  • 您会在整个代码中运行 tryCatch 吗?我基本上只想要 1 条通用错误消息。
  • 不可能在整个应用程序中运行 tryCatch。

标签: r shiny


【解决方案1】:

您可以使用 css 更改默认文本:

tags$head(tags$style(".shiny-output-error{visibility: hidden}")),

tags$head(tags$style(".shiny-output-error:after{content: 'Invalid username. Please try again';
visibility: visible}")),

但正如 greg L 所说,任何错误都会出现此消息 - 因此您应该选择一个全局保存的文本。

【讨论】:

  • visible} 之后应该有一个 " 吗?
猜你喜欢
  • 2018-06-04
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
  • 2012-01-24
  • 1970-01-01
  • 2013-01-19
  • 2017-03-09
相关资源
最近更新 更多