This function creates a custom value box that displays a value and subtitle, plus a hidden footer section that slides down on click to reveal extra content.
Usage
valueBoxDropdown(
value,
subtitle,
icon = NULL,
footer = NULL,
id = NULL,
color = "primary",
width = 3
)
valueBoxDropdownOutput(outputId, width = 4)
renderValueBoxDropdown(expr, env = parent.frame(), quoted = FALSE)Arguments
- value
The value to display in the box. Usually a number or short text.
- subtitle
Subtitle text.
- icon
An icon tag, created by
icon.Optional html content for the footer of the box.
- id
valuebox ID. If null (default), a random ID is generated.
- color
The color of the item. This determines the item's background color. Valid colors are defined as follows:
primary: #007bff .secondary: #6c757d .info: #17a2b8 .success: #28a745 .warning: #ffc107 .danger: #dc3545 .gray-dark: #343a40 .gray: #adb5bd .white: #fff .indigo: #6610f2 .lightblue: #3c8dbc .navy: #001f3f .purple: #605ca8 .fuchsia: #f012be .pink: #e83e8c .maroon: #d81b60 .orange: #ff851b .lime: #01ff70 .teal: #39cccc .olive: #3d9970 .
- width
The width of the box, using the Bootstrap grid system. This is used for row-based layouts. The overall width of a region is 12, so the default width of 4 occupies 1/3 of that width. For column-based layouts, use
NULLfor the width; the width is set by the column that contains the box.- outputId
Output variable name.
- expr
An expression that returns a Shiny tag object,
HTML(), or a list of such objects.- env
The parent environment for the reactive expression. By default, this is the calling environment, the same as when defining an ordinary non-reactive expression. If
expris a quosure andquotedisTRUE, thenenvis ignored.- quoted
If it is
TRUE, then thequote()ed value ofexprwill be used whenexpris evaluated. Ifexpris a quosure and you would like to use its expression as a value forexpr, then you must setquotedtoTRUE.
Examples
# Use valueBoxDropdown in a static bs4Dash UI (no dynamic behaviour)
if (interactive()) {
library(shiny)
library(bs4Dash)
# Define UI with a single value box in the dashboard body
ui <- dashboardPage(
dashboardHeader(title = "My Dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
valueBoxDropdown(
value = 150,
subtitle = "New Orders",
icon = icon("shopping-cart"),
color = "primary", width = 6,
footer = div("Additional details about orders...")
),
valueBoxDropdown(
value = "50%",
subtitle = "Share of Preference",
icon = icon("percent"),
color = "primary", width = 6,
footer = div("Additional details about orders...")
)
)
)
)
server <- function(input, output) { }
shinyApp(ui, server)
}
# Dynamic valueBoxDropdown with custom CSS styling for the dropdown footer.
if (interactive()) {
library(shiny)
library(bs4Dash)
# Define custom CSS to style the dropdown footer (white background, black text, left-aligned)
custom_css <- "
.my-dropdown-footer {
background-color: white !important;
color: black !important;
text-align: left;
}"
ui <- dashboardPage(
dashboardHeader(title = "Custom Styled Value Box"),
dashboardSidebar(),
dashboardBody(# Insert custom CSS into the app
tags$head(tags$style(HTML(
custom_css
))), # UI layout: an input and a valueBoxDropdownOutput to display the value
fluidRow(
column(
width = 4,
numericInput(
"value",
"Set Value:",
min = 0,
max = 100,
value = 42
)
),
column(width = 8, valueBoxDropdownOutput("customBox", width = 12))
))
)
server <- function(input, output) {
output$customBox <- renderValueBoxDropdown({
valueBoxDropdown(
value = input$value,
subtitle = "Current Value",
icon = icon("chart-line"),
color = "info",
width = 12,
# Apply the custom CSS class to the footer content
footer = div(
class = "my-dropdown-footer",
tags$strong("Details:"),
" The value is ",
input$value,
br(),
"Updated at ",
format(Sys.time(), "%H:%M:%S")
)
)
})
}
shinyApp(ui, server)
}