【问题标题】:Render title in R shiny box dynamically动态渲染 R 闪亮框中的标题
【发布时间】:2018-06-12 03:40:00
【问题描述】:

我正在尝试动态渲染我在 R 中使用的框的标题。

到目前为止,盒子代码看起来像这样

 box( title = "lorem ipsum",
        width = 6,
        solidHeader = TRUE,
        status = "primary",
        tableOutput("consumption"),
        collapsible = T
      )

是否可以在服务器中使用渲染文本并将文本作为标题传递:

 con1 <- renderText({
   if (age() == FALSE)
       {
         return("lorem1")

       }
       else
       {
         return("lorem2")
       }
 })

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您应该将renderText 的输出存储为output$x,其中x 是任意的,因此您可以在框的标题参数中将该元素称为textOutput('x')。因此,一个工作示例如下所示。希望这会有所帮助!



    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(
        checkboxInput('mybox',label = 'Title'),
        box(title=textOutput('title'),
            width = 6,
            solidHeader = TRUE,
            status = "primary",
            p('Use the checkbox to change the title of this box.')
        )
      )
    )
    
    server <- function(input, output) {
      output$title <- renderText({ifelse(!input$mybox,'Title 1','Title 2')})
    }
    
    shinyApp(ui,server)
    

    【讨论】:

      猜你喜欢
      • 2021-06-17
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 2015-10-19
      • 1970-01-01
      • 2018-08-14
      相关资源
      最近更新 更多