title: R shinydashboard - show/hide multiple menuItems based on user input
body: <p>The idea is to have a user input (access code), based on which different menuItems can be accessed. So basically we have a custom version of app available based on user's requirement.</p>
  
  <p>A working example for 3 menuItems is as follow:</p>
  
  <pre><code>library(shiny)
  library(shinydashboard)
  library(shinyjs)
  
  ui &lt;- dashboardPage(
                      dashboardHeader(title = "SHOW/HIDE MULTIPLE MENU ITEMS"),
                      dashboardSidebar(
                      useShinyjs(),
                      sidebarMenu(
                          id = "tabs",
                          hidden(
                          menuItem("MENU ITEM 1", tabName = "mi1"),
                          menuItem("MENU ITEM 2", tabName = "mi2"),
                          menuItem("MENU ITEM 3", tabName = "mi3")
                          ),
                          textInput(inputId = "accessToken", label = "Access Code", value = "Show/Hide Menu Items.")
                      )
                      ),
                      dashboardBody()
  
  )
  
  server &lt;- function (input, output, session){
  observeEvent(input$accessToken,{
      if(input$accessToken == "001"){
      hide(selector = "ul li:eq(0)")
      hide(selector = "ul li:eq(1)")
      show(selector = "ul li:eq(2)")
      } else if (input$accessToken == "010"){
          hide(selector = "ul li:eq(0)")
          show(selector = "ul li:eq(1)")
          hide(selector = "ul li:eq(2)")
      } else if (input$accessToken == "011"){
          hide(selector = "ul li:eq(0)")
          show(selector = "ul li:eq(1)")
          show(selector = "ul li:eq(2)")
      } else if (input$accessToken == "100"){
          show(selector = "ul li:eq(0)")
          hide(selector = "ul li:eq(1)")
          hide(selector = "ul li:eq(2)")
      } else if (input$accessToken == "101"){
          show(selector = "ul li:eq(0)")
          hide(selector = "ul li:eq(1)")
          show(selector = "ul li:eq(2)")
      } else if (input$accessToken == "110"){
          show(selector = "ul li:eq(0)")
          show(selector = "ul li:eq(1)")
          hide(selector = "ul li:eq(2)")
      } else if (input$accessToken == "111"){
          show(selector = "ul li:eq(0)")
          show(selector = "ul li:eq(1)")
          show(selector = "ul li:eq(2)")
      } else{
      hide(selector = "ul li") 
      }
  })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>This works perfectly fine with all combinations of 3 menuItems visible for a unique access code.</p>
  
  <p>BUT as you can see this is a lot of repetitive code for accessing 3 menuItems. </p>
  
  <p>In actual I have 10 or even higher number of menuItems, so overall the number of if else statements are going to increase exponentially.</p>
  
  <p>WHAT I HAVE TRIED:</p>
  
  <p>I thought about this logic: For 10 menuItems, have an access code of 10 digits, where each digit can have a value 0 (hide) or 1 (show).</p>
  
  <pre><code>observeEvent(input$accessToken, {
      tokenStr &lt;- input$accessToken
      tokenStrShow &lt;- which(strsplit(tokenStr, "")[[1]]=="1")
      tokenStrHide &lt;- which(strsplit(tokenStr, "")[[1]]=="0")
      for (i in tokenStrShow){
          # some logic to show all menuItems with value 1
          # FOLLOWING DOESNOT WORK
          # paste0("show(selector='ul li:eq(",i,")'")
      }
  })
  </code></pre>
  
  <p>I also came across <a href="https://stackoverflow.com/questions/15072532/show-hide-multiple-elements-based-on-query-string-value">THIS</a> javascript logic which I am trying to implement. But I do not know how to do it in Shiny.</p>