Add nested sidebar to page_navbar in bslib

77 Views Asked by At

I have the following app:

library(bslib)
library(shiny)

id <- "hi"
ns <- NS(id)
page_navbar(
  id = ns("navbar"),
  title = "Example App",
  sidebar =  sidebar(
    id = ns("sidebar"),
    open = "open"
  ),
  nav_panel(
    title = "Overview", 
    h1("Overview")),
  nav_panel(
    title = "Table", 
    h1("table"))
)
)

and I would like to add a second (closed) sidebar on the right hand side. According to the documentation that is possible link with page_fillable(), by my approaches do not get me on the right track when I stick to page_navbar. Any hints?

My approach:

page_navbar(
  layout_sidebar(
    sidebar = sidebar("Left sidebar"),
    layout_sidebar(
      sidebar = sidebar("Right sidebar", position = "right", open = FALSE),
    )
  ),
  nav_panel(
    title = "Overview", 
    h1("Overview")),
  nav_panel(
    title = "Table", 
    h1("table"))
  )
)
1

There are 1 best solutions below

1
Stéphane Laurent On BEST ANSWER

Looks like it is not possible with page_navbar, but you can get something close with navset_underline.

ui <- page_fillable(
  h1("Left and right sidebar", class = "px-3 my-3"),
  layout_sidebar(
    sidebar = sidebar("Left sidebar"),
    layout_sidebar(
      sidebar = sidebar("Right sidebar", position = "right", open = FALSE),
      navset_underline(
        nav_panel(
          title = "Overview", 
          h1("Overview")),
        nav_panel(
          title = "Table", 
          h1("table"))
      ),
      border = FALSE
    ),
    border_radius = FALSE,
    fillable = TRUE,
    class = "p-0"
  )
)

shinyApp(
  ui = ui,
  server = function(input, output){}
)