How to combine top navigation (navbarPage) and a sidebar menu (sidebarMenu) in shiny

前端 未结 3 1062
长发绾君心
长发绾君心 2021-02-05 16:10

I have a shiny app (using navbarPage) with many tabs and would like to add a sidebarMenu that can be seen no matter which tab is selected. The input values in the sidebar have a

3条回答
  •  执念已碎
    2021-02-05 17:06

    You could use sidebarLayout and do something like this:

    ui <- fluidPage(sidebarLayout(
      sidebarPanel(navlistPanel(
        widths = c(12, 12), "SidebarMenu",
        tabPanel(selectizeInput('case', 'Pick a case', selected="A", choices = c("A", "B"), multiple = FALSE)),
        tabPanel(numericInput('num', 'Number', min = 1, max = 10, value = 1, step = 1))
      )),
          mainPanel(navbarPage(title = "nav w/ sidebarMenu",
                                
                                tabPanel(h4("Perspective 1"),
                                         tabsetPanel(
                                           tabPanel("Subtab 1.1",
                                                    plotOutput("plot11")),
                                           tabPanel("Subtab 1.2")
                                         )),
                                tabPanel(h4("Perspective 2"),
                                         tabsetPanel(
                                           tabPanel("Subtab 2.1"),
                                           tabPanel("Subtab 2.2")
                                         )))
          
          )
        ))
    

    You get something like this:

    Another option would be using fluidRow function. Something like this:

      ui <- fluidPage(
        fluidRow(
          column(3, navlistPanel(
            widths = c(12, 12), "SidebarMenu",
            tabPanel(selectizeInput('case', 'Pick a case', selected="A", choices = c("A", "B"), multiple = FALSE)),
            tabPanel(numericInput('num', 'Number', min = 1, max = 10, value = 1, step = 1))
          )),
          column(9,  navbarPage(title = "nav w/ sidebarMenu",
                                 
                                 tabPanel(h4("Perspective 1"),
                                          tabsetPanel(
                                            tabPanel("Subtab 1.1",
                                                     plotOutput("plot11")),
                                            tabPanel("Subtab 1.2")
                                          )),
                                 tabPanel(h4("Perspective 2"),
                                          tabsetPanel(
                                            tabPanel("Subtab 2.1"),
                                            tabPanel("Subtab 2.2")
                                          ))))
          
          
        )
          )
        
    

    To get this:

    Hope it helps!

提交回复
热议问题