The value boxes in bslib are attractive and fulfill a need when dashboarding. However, there doesn't seem to be a straightforward way to populate them with reactive (non-static) values without breaking the formatting and therefore reducing the power to communicate important results.
Here's output from my example app (code at bottom)
The value
in the bottom value_box
will respond to the slider, but textOutput
and similar functions wrap it in a <p>
tag and that makes it so that the value is no longer formatted.
Is there a clean way to put a reactive value in my value_box without messing up my formatting?
library(shiny)
library(bslib)
# Define UI for app that draws a histogram ----
ui <- bslib::page(
# Input: Slider ----
sliderInput(inputId = "number",
label = "number to display",
min = 1,
max = 50,
value = 30),
# Output: Value Box Formatted ----
bslib::value_box(
title = "Good formatting",
value = 30
),
# Output: Value Box Broken formatting ----
bslib::value_box(
title = "Bad formatting",
value = textOutput("out_text")
)
)
# Define server logic required to draw a histogram ----
server <- function(input, output) {
output$out_text <- renderText(input$number)
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
Hopefully this will improve in the future, but for now, I would change textOutput("out_text")
textOutput("out_text", container = h2)