在闪亮的仪表板框的右上角添加操作按钮(图标)

Adding action button (icon) on top right corner of the shiny dashboard box

我需要在闪亮的仪表板框的右上角有一个操作按钮图标。下面的代码将图标 'refresh' 和 'plus' 附加到 'Title1' 旁边。但是,我需要将图标放置在 header 栏的右侧(类似于 windows 应用程序中最小化、恢复和关闭按钮的位置)。

library(shiny)
library(shinydashboard)

body <- dashboardBody(
  fluidRow(
    box(
      title = p("Title 1", 
                actionButton("titleBtId", "", icon = icon("refresh"),
                             class = "btn-xs", title = "Update"),
                actionButton('titleBtid2', '', icon = icon('plus'),
                             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$boxContentUI2 <- renderUI({
    input$titleBtId
    pre(paste(sample(LETTERS,10), collapse = ", "))
  })  
}

shinyApp(ui = ui, server = server)

为您的操作按钮添加带有绝对定位的样式声明。

library(shiny)
library(shinydashboard)

body <- dashboardBody(
  fluidRow(
    box(
      title = p("Title 1", 
                actionButton("titleBtId", "", icon = icon("refresh"),
                             class = "btn-xs", title = "Update", style = "position: absolute; right: 40px"),
                actionButton('titleBtid2', '', icon = icon('plus'),
                             class = 'btn-xs', title = 'update', style = "position: absolute; right: 10px")
      ), 
      width = 4, solidHeader = TRUE, status = "warning",
      uiOutput("boxContentUI2")
    )
  )
)

ui <- dashboardPage(
  dashboardHeader(title = "Row layout"),
  dashboardSidebar(),
  body
)

server = function(input, output, session) { 
  
  output$boxContentUI2 <- renderUI({
    input$titleBtId
    pre(paste(sample(LETTERS,10), collapse = ", "))
  })  
}

shinyApp(ui = ui, server = server)