You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在shinydashboard中将tabBox的标题置于标签页上方

解决方案

通过注入自定义CSS修改tabBox的默认布局即可实现需求,修改后的完整可运行代码如下:

library(shiny)
library(shinydashboard)
ui = dashboardPage(
  dashboardHeader(title = "tabBoxes"), 
  dashboardSidebar(),
  dashboardBody(
    # 注入自定义CSS
    tags$head(
      tags$style(HTML("
        .custom-tabbox .box-header {
          display: flex;
          flex-direction: column;
          align-items: flex-start;
        }
        .custom-tabbox .box-header > .box-title {
          float: none;
          margin-bottom: 10px;
        }
      "))
    ),
    fluidRow(
      tabBox(
        title = HTML("Hello friend<br>"),
        # 给当前tabBox添加自定义类名,仅修改单个tabBox的样式
        class = "custom-tabbox",
        tabPanel("merp", "hi there"),
        tabPanel("derp", "hello"),
        tabPanel("herp", "howdy")
      )
    )
  )
)

server = function(input, output) {
  output$tabset1Selected <- renderText({
    input$tabset1
  })
}
shinyApp(ui = ui, server = server)

如果需要全局修改所有tabBox的标题位置,直接去掉CSS选择器里的.custom-tabbox前缀即可,不需要给每个tabBox单独添加自定义类。

内容的提问来源于stack exchange,提问作者Marissa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 07:24:03