How can I recreate the visual look of base shiny navbarPage and tabPanel with a sidebar in bslib?

I am trying to use bslib to theme my Shiny application but I am having trouble understanding how to utilize the layout and card properties to create the base Shiny navbarPage and tabPanel look.

I have provided code below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>library(shiny)
library(bslib)
library(DT)
library(dplyr)
options(shiny.port = 8080)
test_theme <- bs_theme(
bootswatch = "cosmo",
version = 5,
bg = "#FFFFFF", # Replaces default white with Adaptive off-white
fg = "#000000", # Default black
"navbar-bg" = "#0169d6",
"navbar-light-bg" = "#0169d6",
"navbar-light-color" = "#F6F6F6",
"navbar-light-hover-color" = "#0B2663",
"navbar-light-active-color" = "#F6F6F6",
)
# UI/Server for Module_1
module_1_ui <- function(id) {
ns <- NS(id)
nav_panel(
title = "Main",
layout_columns(
col_widths = c(3, 9),
card(
title = "Card 1",
max_height = "150px",
class = "well",
textInput(ns("textInput"), 'Enter text')
),
layout_columns(
col_widths = 12,
card(
height = "100vh",
style = "border: none;",
title = "Card 2",
uiOutput(ns('textOutput'))
)
)
)
)
# tabPanel("Main", fluid = TRUE,
# sidebarLayout(
# sidebarPanel(
# textInput(ns('textInput'), 'Enter text')
# ),
# mainPanel(
# uiOutput(ns('textOutput'))
# )
# )
# )
}
module_1_server <- function(id, session) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
output$textOutput <- renderUI({
req(input$textInput)
HTML(paste0('You entered: ', input$textInput))
})
})
}
# UI/Server for Module_2
module_2_ui <- function(id) {
ns <- NS(id)
nav_panel(
title = "Side",
layout_columns(
col_widths = c(3, 9),
card(
title = "Card 1",
class = "well",
HTML("This always shows!"),
br(),
uiOutput(ns("selectUI")),
conditionalPanel(
condition = sprintf("input['%s'] == 'Test2'", ns("side_tabsets")),
uiOutput(ns("group_by_select")),
actionButton(ns("button3"), "Button 3")
)
),
layout_columns(
col_widths = 12,
card(
height = "100vh",
style = "border: none;",
title = "Card 2",
uiOutput(ns('sideOutput'))
)
)
)
)
# tabPanel("Side", fluid = TRUE,
# sidebarLayout(
# sidebarPanel(
# HTML("This always shows!"),
# br(),
# uiOutput(ns("selectUI")),
# conditionalPanel(
# condition = sprintf("input['%s'] == 'Test2'", ns("side_tabsets")),
# uiOutput(ns("group_by_select")),
# actionButton(ns("button3"), "Button 3")
# )
# ),
# mainPanel(
# uiOutput(ns('sideOutput'))
# )
# )
# )
}
module_2_server <- function(id, session) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
output$selectUI <- renderUI({
selectInput(ns("data_select"), "Select Data", choices = colnames(iris), multiple = TRUE)
})
output$sideOutput <- renderUI({
tabsetPanel(
id = ns("side_tabsets"),
tabPanel(title = "Test1", br(), fluidRow(column(DT::DTOutput(ns("table")), width = 6))),
tabPanel(title = "Test2", br(), fluidRow(column(DT::DTOutput(ns("group_by_table")), width = 6)))
)
})
output$group_by_select <- renderUI({
selectInput(ns("group_by_select"), "Group By", choices = colnames(iris))
})
output$table <- DT::renderDT({
iris %>% select(input$data_select)
})
output$group_by_table <- DT::renderDT({
NULL
})
observeEvent(input$button3, {
output$group_by_table <- DT::renderDT({
iris %>% select(input$data_select) %>% group_by(input$group_by_select) %>% summarise(n = n())
})
})
})
}
# Overall UI
ui <- page_fluid(
theme = test_theme,
page_navbar(title = "",
module_1_ui("main"),
module_2_ui("side")
)
)
# Overall Server
server <- function(input, output, session) {
module_1_server("main", session)
module_2_server("side", session)
}
shinyApp(ui = ui, server = server)
</code>
<code>library(shiny) library(bslib) library(DT) library(dplyr) options(shiny.port = 8080) test_theme <- bs_theme( bootswatch = "cosmo", version = 5, bg = "#FFFFFF", # Replaces default white with Adaptive off-white fg = "#000000", # Default black "navbar-bg" = "#0169d6", "navbar-light-bg" = "#0169d6", "navbar-light-color" = "#F6F6F6", "navbar-light-hover-color" = "#0B2663", "navbar-light-active-color" = "#F6F6F6", ) # UI/Server for Module_1 module_1_ui <- function(id) { ns <- NS(id) nav_panel( title = "Main", layout_columns( col_widths = c(3, 9), card( title = "Card 1", max_height = "150px", class = "well", textInput(ns("textInput"), 'Enter text') ), layout_columns( col_widths = 12, card( height = "100vh", style = "border: none;", title = "Card 2", uiOutput(ns('textOutput')) ) ) ) ) # tabPanel("Main", fluid = TRUE, # sidebarLayout( # sidebarPanel( # textInput(ns('textInput'), 'Enter text') # ), # mainPanel( # uiOutput(ns('textOutput')) # ) # ) # ) } module_1_server <- function(id, session) { moduleServer(id, function(input, output, session) { ns <- session$ns output$textOutput <- renderUI({ req(input$textInput) HTML(paste0('You entered: ', input$textInput)) }) }) } # UI/Server for Module_2 module_2_ui <- function(id) { ns <- NS(id) nav_panel( title = "Side", layout_columns( col_widths = c(3, 9), card( title = "Card 1", class = "well", HTML("This always shows!"), br(), uiOutput(ns("selectUI")), conditionalPanel( condition = sprintf("input['%s'] == 'Test2'", ns("side_tabsets")), uiOutput(ns("group_by_select")), actionButton(ns("button3"), "Button 3") ) ), layout_columns( col_widths = 12, card( height = "100vh", style = "border: none;", title = "Card 2", uiOutput(ns('sideOutput')) ) ) ) ) # tabPanel("Side", fluid = TRUE, # sidebarLayout( # sidebarPanel( # HTML("This always shows!"), # br(), # uiOutput(ns("selectUI")), # conditionalPanel( # condition = sprintf("input['%s'] == 'Test2'", ns("side_tabsets")), # uiOutput(ns("group_by_select")), # actionButton(ns("button3"), "Button 3") # ) # ), # mainPanel( # uiOutput(ns('sideOutput')) # ) # ) # ) } module_2_server <- function(id, session) { moduleServer(id, function(input, output, session) { ns <- session$ns output$selectUI <- renderUI({ selectInput(ns("data_select"), "Select Data", choices = colnames(iris), multiple = TRUE) }) output$sideOutput <- renderUI({ tabsetPanel( id = ns("side_tabsets"), tabPanel(title = "Test1", br(), fluidRow(column(DT::DTOutput(ns("table")), width = 6))), tabPanel(title = "Test2", br(), fluidRow(column(DT::DTOutput(ns("group_by_table")), width = 6))) ) }) output$group_by_select <- renderUI({ selectInput(ns("group_by_select"), "Group By", choices = colnames(iris)) }) output$table <- DT::renderDT({ iris %>% select(input$data_select) }) output$group_by_table <- DT::renderDT({ NULL }) observeEvent(input$button3, { output$group_by_table <- DT::renderDT({ iris %>% select(input$data_select) %>% group_by(input$group_by_select) %>% summarise(n = n()) }) }) }) } # Overall UI ui <- page_fluid( theme = test_theme, page_navbar(title = "", module_1_ui("main"), module_2_ui("side") ) ) # Overall Server server <- function(input, output, session) { module_1_server("main", session) module_2_server("side", session) } shinyApp(ui = ui, server = server) </code>
library(shiny)
library(bslib)
library(DT)
library(dplyr)

options(shiny.port = 8080)

test_theme <- bs_theme(
    bootswatch = "cosmo",
    version = 5,
    bg = "#FFFFFF", # Replaces default white with Adaptive off-white
    fg = "#000000", # Default black
    "navbar-bg" = "#0169d6",
    "navbar-light-bg" = "#0169d6",
    "navbar-light-color" = "#F6F6F6",
    "navbar-light-hover-color" = "#0B2663",
    "navbar-light-active-color" = "#F6F6F6",
    )

# UI/Server for Module_1
module_1_ui <- function(id) {
  ns <- NS(id)

  nav_panel(
    title = "Main",
    layout_columns(
      col_widths = c(3, 9),
      card(
        title = "Card 1",
        max_height = "150px",
        class = "well",
        textInput(ns("textInput"), 'Enter text')
      ),
      layout_columns(
        col_widths = 12,
        card(
          height = "100vh",
          style = "border: none;",
          title = "Card 2",
          uiOutput(ns('textOutput'))
        )
      )
    )
  )

  # tabPanel("Main", fluid = TRUE,
  #     sidebarLayout(
  #       sidebarPanel(
  #         textInput(ns('textInput'), 'Enter text')
  #       ),
  #       mainPanel(
  #         uiOutput(ns('textOutput'))
  #       )
  #     )
  # )
  
}

module_1_server <- function(id, session) {
  moduleServer(id, function(input, output, session) {
    ns <- session$ns

    output$textOutput <- renderUI({
      req(input$textInput)
      HTML(paste0('You entered: ', input$textInput))
    })
    
  })

}
# UI/Server for Module_2
module_2_ui <- function(id) {
  ns <- NS(id)

  nav_panel(
    title = "Side",
    layout_columns(
      col_widths = c(3, 9),
      card(
        title = "Card 1",
        class = "well",
        HTML("This always shows!"),
        br(),
        uiOutput(ns("selectUI")),
        conditionalPanel(
                  condition =  sprintf("input['%s'] == 'Test2'", ns("side_tabsets")),
                  uiOutput(ns("group_by_select")),
                  actionButton(ns("button3"), "Button 3")
                )
      ),
      layout_columns(
        col_widths = 12,
        card(
          height = "100vh",
          style = "border: none;",
          title = "Card 2",
          uiOutput(ns('sideOutput'))
        )
      )
    )
  )

  # tabPanel("Side", fluid = TRUE,
  #     sidebarLayout(
  #       sidebarPanel(
  #         HTML("This always shows!"),
  #         br(),
  #         uiOutput(ns("selectUI")),
  #         conditionalPanel(
  #                 condition =  sprintf("input['%s'] == 'Test2'", ns("side_tabsets")),
  #                 uiOutput(ns("group_by_select")),
  #                 actionButton(ns("button3"), "Button 3")
  #               )
  #       ),
  #       mainPanel(
  #         uiOutput(ns('sideOutput'))
  #       )
  #     )
  # )
}

module_2_server <- function(id, session) {

  moduleServer(id, function(input, output, session) {
    ns <- session$ns

    output$selectUI <- renderUI({
      selectInput(ns("data_select"), "Select Data", choices = colnames(iris), multiple = TRUE)
    })

    output$sideOutput <- renderUI({
      tabsetPanel(
        id = ns("side_tabsets"),
        tabPanel(title = "Test1", br(), fluidRow(column(DT::DTOutput(ns("table")), width = 6))),
        tabPanel(title = "Test2", br(), fluidRow(column(DT::DTOutput(ns("group_by_table")), width = 6)))
      )
    })

    output$group_by_select <- renderUI({
      selectInput(ns("group_by_select"), "Group By", choices = colnames(iris))
    })

    output$table <- DT::renderDT({
      iris %>% select(input$data_select)
    })

    output$group_by_table <- DT::renderDT({
      NULL
    })

    observeEvent(input$button3, {
      output$group_by_table <- DT::renderDT({
        iris %>% select(input$data_select) %>% group_by(input$group_by_select) %>% summarise(n = n())
      })
    })
  })
}

# Overall UI
ui <- page_fluid(
  theme = test_theme,
  page_navbar(title = "",
    module_1_ui("main"),
    module_2_ui("side")
  )
)

# Overall Server
server <- function(input, output, session) {
  module_1_server("main", session)
  module_2_server("side", session)
}



shinyApp(ui = ui, server = server)

I want the appearance to match the commented out bit of my original Shiny code. The few things I cannot get to work well is having a floating sidebar using card that does not span the entire page:

Why do the dropdown menus get cutoff?

I want the sidebar to grow as more elements get added but not take up the entire page.

I have tried using the height, min_height, and max_height properties inside of card and it does not grow properly and always assumes the max_height.

New contributor

Hpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật