I'm starting to build out a new shinydashboard and I'm creating a template that follows our company brand. I'm wanting to add additional background color options to the boxes that are our brand colors, i.e. "bg-company-red" and "bg-company-yellow". In the shinydashboard code for box it only allows validColors, so I can't just use my own tags and add the css for it.
My two options seem to be:
- Override the css for the validColors, but I don't like this because I'd like to share this with others in the company and if they happen to use some of the validColors they would get a color they don't expect if they loaded my css.
- Create a local copy of the box function that doesn't check for validColors so I can create my own background color tags. This isn't great for maintenance purposes.
I understand including the validColor check for the status tags because there are only so many statuses, but is it really needed for the background color? The default colors provide a nice color palette but it limits anyone that wants to easily customize their boxes. Is there something I'm missing? An easier solution?
#this is what I wanted to do (the corresponding css would be in a css file loaded to my app)
box(title = "test", background = "company-red", solidHeader = TRUE,
collapsible = TRUE, plotOutput(ns("plot1")))
#I would have to do this and override the default css for bg-red
box(title = "test", background = "red", solidHeader = TRUE,
collapsible = TRUE, plotOutput(ns("plot1")))
Here's the link to the box code on github for reference, the chunk of box code also below: https://github.com/rstudio/shinydashboard/blob/master/R/boxes.R
box <- function(..., title = NULL, footer = NULL, status = NULL,
solidHeader = FALSE, background = NULL, width = 6,
height = NULL, collapsible = FALSE, collapsed = FALSE) {
boxClass <- "box"
if (solidHeader || !is.null(background)) {
boxClass <- paste(boxClass, "box-solid")
}
if (!is.null(status)) {
validateStatus(status)
boxClass <- paste0(boxClass, " box-", status)
}
if (collapsible && collapsed) {
boxClass <- paste(boxClass, "collapsed-box")
}
if (!is.null(background)) {
validateColor(background)
boxClass <- paste0(boxClass, " bg-", background)
}
style <- NULL
if (!is.null(height)) {
style <- paste0("height: ", validateCssUnit(height))
}
titleTag <- NULL
if (!is.null(title)) {
titleTag <- h3(class = "box-title", title)
}
collapseTag <- NULL
if (collapsible) {
buttonStatus <- status %OR% "default"
collapseIcon <- if (collapsed) "plus" else "minus"
collapseTag <- div(class = "box-tools pull-right",
tags$button(class = paste0("btn btn-box-tool"),
`data-widget` = "collapse",
shiny::icon(collapseIcon)
)
)
}
headerTag <- NULL
if (!is.null(titleTag) || !is.null(collapseTag)) {
headerTag <- div(class = "box-header",
titleTag,
collapseTag
)
}
div(class = if (!is.null(width)) paste0("col-sm-", width),
div(class = boxClass,
style = if (!is.null(style)) style,
headerTag,
div(class = "box-body", ...),
if (!is.null(footer)) div(class = "box-footer", footer)
)
)
}