The bslib::card function has a class argument which allows to set the class of a card container. In contrast, the navset_card_tab function does not have such argument. However, when I explore the content of the Shiny app using the web developper tools, I can add the 'bg-dark' class to the div defining the header area (which is already assigned to class="card-header bslib-navs-card-title") and change this element to "dark mode".
Is there a way to do that throught the Shiny app code?
Okay - it's almost always a good idea to work on example code.
I'm assuming you specifically want to modify navset_card_tab headers (otherwise I'd suggest looking into this article on theming with bslib).
We can modify the classes of the header via JS, please check the following:
library(shiny)
library(bslib)
library(htmltools)
ui <- page_sidebar(
tags$head(
tags$script(HTML(
"$(document).on('shiny:connected', function(event) {
const collection = document.getElementsByClassName('card-header bslib-navs-card-title');
if(collection){
for (let i = 0; i < collection.length; i++) {
var targetelement = collection[i];
targetelement.classList.add('bg-dark');
};
};
});"
))
),
title = "My dashboard",
sidebar = "Sidebar",
navset_card_tab(
height = 450,
full_screen = TRUE,
title = "HTML Widgets",
nav_panel(
"Plotly",
card_title("A plotly plot")
),
nav_panel(
"Leaflet",
card_title("A leaflet plot")
),
nav_panel(
shiny::icon("circle-info"),
markdown("Learn more about [htmlwidgets](http://www.htmlwidgets.org/)")
)
)
)
shinyApp(ui, function(input, output, session) {})