【问题标题】:Invalid argument type with verbatimTextOutput in shiny无效的参数类型与闪亮的verbatimTextOutput
【发布时间】:2020-09-15 19:46:22
【问题描述】:

我很难理解 Shiny 模块的工作原理。我正在使用 Golem 模板 (https://github.com/ThinkR-open/golem) 构建应用程序。

编辑 我意识到我的错误与任何模块无关,因此生成了一个最小示例。要查看旧代码,请查看编辑历史记录

library(shiny)

app_ui <- function() {
  fluidPage(
    textInput(inputId = "test", label = "Labley", value = "val"),
    verbatimTextOutput(outputId = "out", placeholder = "None")
  )
}

app_server <- function(input, output, session) {
  output$out <- renderText(expr = input$test)
}

shinyApp(ui = app_ui, server = app_server)

这会导致:

Error in !: invalid argument type

如何让 UI 打印我的文本输入?

【问题讨论】:

  • 我已经阅读了所有 Shiny 的文章,并且还参考了 engineering-shiny.org 和 mastering-shiny.org 等资源,但我无法完全理解响应式*的概念、渲染*和模块。
  • text() 运行text 函数,用于在绘图上添加一些文本。我想你想要input$text 而不是text()
  • 感谢输入!另外,我意识到错误与模块无关,因此将示例更正为功能最少的示例
  • app_ui &lt;- fluidPage(......),而不是app_ui &lt;- function() ......

标签: r shiny


【解决方案1】:

@KasperThystrupKarstensen 这里的问题是,verbatimTextOutput 的占位符参数需要一个布尔输入(参见?verbatimTextOutput 中的用法)。但是,您传递了一个字符串。

这行得通:

library(shiny)

app_ui <- fluidPage(
  textInput(
    inputId = "test",
    label = "Labley",
    value = "val"
  ),
  verbatimTextOutput(outputId = "out", placeholder = FALSE)
)

app_server <- function(input, output, session) {
  output$out <- renderText(expr = input$test)
}

shinyApp(ui = app_ui, server = app_server)

?verbatimTextOutput:

占位符:如果输出为空或NULL,应为空矩形 显示为占位符? (不影响行为时 非空输出)

【讨论】:

  • 啊,现在我明白了,我错误地假设像大多数其他闪亮的 input* 函数一样,占位符参数需要一个字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-16
  • 1970-01-01
  • 2022-11-10
相关资源
最近更新 更多