R Shinydashboard 自定义 CSS 到 valueBox [英] R shinydashboard custom CSS to valueBox
问题描述
我一直在尝试将 valueBox 的颜色更改为自定义颜色(超出 validColors 中可用的颜色),但一直无法这样做.我知道有一种方法可以使用标签来包含自定义 CSS,但我一直无法将它们放在正确的位置.
I have been trying to change the color of the valueBox to a custom color (beyond those available in validColors) but have been unable to do so. I understand there is a way of using tags to include custom CSS however I haven't been able to put them in the right place.
ui<- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(valueBoxOutput("name")
)))
server<- function(input, output){
output$name<- renderValueBox({ valueBox(
("example"), subtitle = "Subtitle text",color="blue")}
)}
非常感谢任何帮助!
推荐答案
您好,您可以覆盖一个 CSS 类以在 ui 中使用 tags$style
添加自定义颜色,如下所示,修改 background-color
用于框颜色(这里是亮黄色)和 color
用于文本颜色.这里只有 color = "yellow"
的框会被修改,因为只有 .small-box.bg-yellow
类被更新.
Hi you can overwrite a CSS class to add a custom color with tags$style
in the ui like below, modify background-color
for the box color (here a flashy yellow) and color
for the text color. Here only box with color = "yellow"
will be modified since only the class .small-box.bg-yellow
is updated.
library("shiny")
library("shinydashboard")
ui<- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$style(".small-box.bg-yellow { background-color: #FFFF00 !important; color: #000000 !important; }"),
fluidRow(
valueBoxOutput("name1"),
valueBoxOutput("name2")
)
)
)
server<- function(input, output){
output$name1 <- renderValueBox({
valueBox("example", subtitle = "Subtitle text", color = "yellow")
})
output$name2 <- renderValueBox({
valueBox("example", subtitle = "Subtitle text", color = "blue")
})
}
shinyApp(ui = ui, server = server)
这篇关于R Shinydashboard 自定义 CSS 到 valueBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!