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


i have shiny app (using navbarpage) many tabs , add sidebarmenu can seen no matter tab selected. input values in sidebar have impact on content of tabs. additionally, should possible hide sidebarmenu in shinydashboard.

i see 2 possible ways:

(a) using shinydashboard , somehow adding top navigation bar or

(b) using navbarpage , somehow adding sidebar menu can hidden.

(a) using shinydashboard, closest want (simplified mwe):

library("shiny") library("shinydashboard")  cases <- list(a=seq(50,500, length.out=10), b=seq(1000,10000, length.out=10))  ui <- dashboardpage(   dashboardheader(title = "dash w/ navbarmenu"),   dashboardsidebar(selectizeinput('case', 'pick case', selected="a", choices = c("a", "b"), multiple = false), numericinput('num', 'number', min = 1, max = 10, value = 1, step = 1)),   dashboardbody(     tabsetpanel(       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")                ))     )   ) )  server <- function(input, output) {   output$plot11 <- renderplot({     hist(rnorm(cases[[input$case]][input$num]))   }) }  shinyapp(ui, server) 

which ugly because navigation bar menu tabsets not part of menu. want is: dashboard_w_navbar

based on post, guess it's not possible include "perspective 1" , "perspective 2" tabs in top menu @ all, using shinydashboard seems not feasible.

(b) using navbarpage, tried using navlistpanel() didn't succeed

(1) make behave sidebarmenu, i.e. overall visible on left side of page ,

(2) add hide functionality. here try:

library("shiny")  cases <- list(a=seq(50,500, length.out=10),               b=seq(1000,10000, length.out=10))  ui <- 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")                             )),                   navlistpanel(widths = c(2, 2), "sidebarmenu",                               tabpanel(selectizeinput('case', 'pick case', selected="a", choices = c("a", "b"), multiple = false)),                               tabpanel(numericinput('num', 'number', min = 1, max = 10, value = 1, step = 1))                  ) )   server <- function(input, output) {   output$plot11 <- renderplot({     hist(rnorm(cases[[input$case]][input$num]))   }) }  shinyapp(ui, server) 

again, want is: nav_w_sidebar

i know, there flexdashboard. not solve problem 3 reasons:

(1) think not possible hide sidebar menu, column , not real sidebar menu,

(2) not reactive require in app,

(3) think datatables don't work, need.

besides, i'd prefer not have change code rmarkdown syntax.

preferably, i'd use navbarpage , add sidebarmenu, because app built using navbarpage.

you use sidebarlayout , this:

ui <- fluidpage(sidebarlayout(   sidebarpanel(navlistpanel(     widths = c(12, 12), "sidebarmenu",     tabpanel(selectizeinput('case', 'pick 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 this: enter image description here

another option using fluidrow function. this:

  ui <- fluidpage(     fluidrow(       column(3, navlistpanel(         widths = c(12, 12), "sidebarmenu",         tabpanel(selectizeinput('case', 'pick 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 this: enter image description here

hope helps!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -