rstudio / bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
https://rstudio.github.io/bslib/
Other
443 stars 49 forks source link

Dashboard design interactions with cards #1055

Closed gadenbuie closed 1 month ago

gadenbuie commented 1 month ago

Bootstrap recommends changing card colors using text-bg-{theme} classes, but this approach reveals a number of tricky problems we've introduced with the dashboard design, as well as issues with the sidebar defaults. (App on shinylive)

Example App ```r library(shiny) library(bslib) library(glue) set.seed(42 + 4) states <- c("base", "default", "primary", "secondary", "info", "success", "warning", "danger", "dark", "light") ui <- page_fillable( # Enable line below to see app without the dashboard design # theme = bs_theme(5, "shiny", "bslib-dashboard-design" = FALSE), layout_column_wrap( width = 200, !!!purrr::map(states, function(state) { card( class = glue("text-bg-{state}"), card_header(glue("My {state} card")), layout_sidebar( sidebar = sidebar( width = 100, lorem::ipsum(1, 1, 3) ), lorem::ipsum(1, 1, 6) ) ) }) ) ) server <- function(input, output, session) { } shinyApp(ui = ui, server = server) ```

With dashboard design (bslib default)

With the dashboard design, using text-bg-{state} results in the following card styles. In particular, the card cap is forced to have a white background and the sidebars are always $body-color text on a $body-bg background.

image

With dashboard design disabled

With the dashboard design disabled, cards are close to the desired state, but the sidebar foreground color is forced to $body-color rather than inheriting.

image

Base Bootstrap

With bs_theme(5, "bootstrap"), we see the following styles where again the sidebar foreground color is problematic.

image