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

如何使用CSS将R Shiny Dashboard的Box标题设置为粗体?

How to Make Shiny Dashboard Box Titles Bold via Custom CSS

Hey there! Since you're already using a custom CSS file for your Shiny Dashboard, making those box titles bold is straightforward. Here's exactly what you need to do:

Step 1: Add CSS Rule to Your Custom File

Shinydashboard wraps box titles in the .box-header container with the class .box-title. To make all box titles bold, drop this rule into your my_style.css file:

/* Make all Shiny Dashboard box titles bold */
.box-header .box-title {
  font-weight: bold;
}

Step 2 (Optional): Target Specific Boxes

If you only want to bold titles for boxes with a specific status (like your primary status box in the example), use a more precise selector:

/* Bold only primary status box titles (with solid header) */
.box.box-primary.box-solid .box-header .box-title {
  font-weight: bold;
}

Step 3: Confirm Your App Setup

Ensure your my_style.css is saved in the www folder of your Shiny app (Shiny automatically checks this directory for static assets). Here's your full, updated ui.R for reference:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Test", tabName = "test", icon = icon("dashboard"))
    )
  ),
  dashboardBody(
    tags$head(
      tags$link(rel = "stylesheet", type = "text/css", href = "my_style.css")
    ),
    tabItems(
      tabItem(tabName = "test",
              fluidRow(
                box(collapsible = TRUE, width = 3, status = "primary", solidHeader = T, title = "Test")
              ))
    )
  )
)

server <- function(input, output) {}

shinyApp(ui, server)

That's all! Run your app, and you'll see your box titles show up in bold.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:33:42