代码之家  ›  专栏  ›  技术社区  ›  hartmut

闪亮-仪表板页面-如何将按钮添加到方框标题

  •  4
  • hartmut  · 技术社区  · 7 年前

    dashboardPage 我用盒子做了一个仪表板。

    我想能够点击某个地方的标题框,以触发一些行动。我知道的唯一一个标题有按钮的情况是可扩展框的情况。有没有可能概括一下,当点击方框标题的某个地方时,会触发一些动作?

    谢谢

    body <- dashboardBody(
      fluidRow(
        box(
          title = "Title 1", width = 4, solidHeader = TRUE, status = "primary",
          "Box content"
        ),
        box(
          title = "Title 1", width = 4, solidHeader = TRUE, status = "warning",
          "Box content"
        )
      )
    )
    # We'll save it in a variable `ui` so that we can preview it in the console
    ui <- dashboardPage(
      dashboardHeader(title = "Row layout"),
      dashboardSidebar(),
      body
    )
    # Preview the UI in the console
    shinyApp(ui = ui, server = function(input, output) { })
    
    1 回复  |  直到 7 年前
        1
  •  11
  •   Geovany    5 年前

    如果你想在盒子标题的右角有一个按钮,你可以修改原来的 box

    一个更简单的解决方案是创建一个带有 actionLink actionButton actionLink 操作按钮 这也将更新框内容。对于第二个框,可以添加一些自定义样式来创建与普通框大小相同的标题。

    library(shiny)
    library(shinydashboard)
    
    body <- dashboardBody(
      fluidRow(
        box(
          title = actionLink("titleId", "Update", icon = icon("refresh")), 
          width = 4, solidHeader = TRUE, status = "primary",
          uiOutput("boxContentUI")
        ),
        box(
          title = p("Title 1", 
                    actionButton("titleBtId", "", icon = icon("refresh"),
                      class = "btn-xs", title = "Update")
          ), 
          width = 4, solidHeader = TRUE, status = "warning",
          uiOutput("boxContentUI2")
        )
      )
    )
    
    ui <- dashboardPage(
      dashboardHeader(title = "Row layout"),
      dashboardSidebar(),
      body
    )
    
    server = function(input, output, session) { 
      output$boxContentUI <- renderUI({
        input$titleId
        pre(paste(sample(letters,10), collapse = ", "))
      }) 
    
      output$boxContentUI2 <- renderUI({
        input$titleBtId
        pre(paste(sample(LETTERS,10), collapse = ", "))
      })  
    }
    
    shinyApp(ui = ui, server = server)