【问题标题】:Prevent textOutput from producing line break防止 textOutput 产生换行符
【发布时间】:2020-06-12 10:58:14
【问题描述】:

我使用 shinydashboard 构建了一个应用程序,并尝试生成一个带有(反应性)文本的框。我在dashboardBody 中的代码是

box("Species was found in ", textOutput("Count1"), "of", Count2, "Sites")

Count1 是响应式的,基于 UI 中的用户输入。 Count2 在 global.R 中定义。

输出是:

Species was found in
1
of 134 Sites

那么,如何删除换行符? paste() 不起作用,因为它只显示 textoutput 元素的 html 代码。

【问题讨论】:

  • 我认为使用 paste 可以满足您的要求:box(paste("Species was found in", textOutput("Count1"), "of", Count2, "Sites"))
  • 正如我所写的 paste() 产生:Species was found in <div id="Count1" class="shiny-text-output"></div> of 134 Sites
  • cat( ) 函数在这里可能会有所帮助。
  • 不,这会产生:ERROR: argument 1 (type 'list') cannot be handled by 'cat'
  • textOutput("Count1", inline = TRUE) 能帮到你吗?

标签: r shiny line break shinydashboard


【解决方案1】:

基于它确实有效的 cmets,所以这里我的解决方案作为答案:

box("Species was found in ", textOutput("Count1", inline = TRUE), "of", Count2, "Sites")

如果没有inline = TRUE,它会将textOuput()放在div中,这样会创建换行符。

【讨论】:

    【解决方案2】:

    包装每个元素应该可以工作:

    box(
        div(style="display: inline-block;","Species was found in "), 
        div(style="display: inline-block;",textOutput("Count1")), 
        div(style="display: inline-block;",paste("of", Count2, "Sites"))
    )
    

    【讨论】:

    • 感谢您的回复,它也有效,但我想@ek-g 的解决方案对我来说更干净一些。
    猜你喜欢
    • 1970-01-01
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多