如何使用CSS将R Shiny Dashboard的Box标题设置为粗体?
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

