title: Create conditional menuitems and menuSubItems in Shiny
body: <p>I found how to create dynamically a menu at: <a href="http://rstudio.github.io/shinydashboard/structure.html#dynamic-content-1" rel="nofollow noreferrer">http://rstudio.github.io/shinydashboard/structure.html#dynamic-content-1</a>.
  But, I cannot figure out how to get what I would need.</p>
  
  <p>With the code given in the link above and if statements, I was able to create or not a WHOLE menu relevant to other inputs in my app.
  But now what I am looking for is flexibility on each items/subitems.
  For instance, for a default menu like this:</p>
  
  <p>Analyses</p>
  
  <ol>
  <li>Analysis 1</li>
  <li>Analysis 2</li>
  <li>Analysis 3</li>
  </ol>
  
  <p>I would like to find a way to only show Analysis 1 and 3 if the files needed for analysis 2 are is not present on the server.</p>
  
  <p>So dependant on my app inputs (drop down menus) and other parameters, I would want to be able to change the menu itself. Is that possible?</p>
  
  <p>So far I have tried to find a way to dynamically concatenate menuItems/subMenuItems but no luck. </p>
  
  <p>I have also tried to cheat and generate strings with the right html tags. But this do not seem to work either. Not sure why yet.</p>
  
  <p>Following up the first comments/answers to my question. I am putting below a minimal example of what I have tried. I appreciate this is an ugly way of doing it and it does not work (no menu appearing). It is all based on Pascallv minimal example in the first answer:</p>
  
  <pre><code>library(shiny)
  library(shinydashboard)
  
  ui &lt;- dashboardPage(
   dashboardHeader(title = "Dynamic sidebar"),
  
    dashboardSidebar(
      sidebarMenuOutput("menu")
    ),
  
    dashboardBody(selectInput(inputId = "SelectFolder", label = "Select my 
    analysis folder", choices = 
                            c(".", "..", "../.."))) 
  )
  
  
  
  server &lt;- function(input, output) {
  
    # whenever input$hide_tab changes through user input, output$menu adapts
    observeEvent(input$SelectFolder,{
  
      content&lt;-list.files(input$SelectFolder)
      menu &lt;- '&lt;ul id="mymenu" class="sidebar-menu"&gt;'
      menu &lt;-paste0(menu,menuItem("analysis 1", tabName = "a1", icon = icon("list-ul")))
     if("app.R" %in% content){
        menu &lt;-paste0(menu,menuItem("analysis 2", tabName = "a2", icon = icon("bar-chart")))
      }
      menu &lt;-paste0(menu,"&lt;/ul&gt;") # end of the whole menu
      output$menu &lt;- renderMenu(menu)
    } )  
  }
  
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>The reason why Pascallv solution does not work for me is because I have a lot of different cases (the menu can be big) and I cannot cover all possible combinations of analyses being present in my folders or not by creating 50+ different menus.
  Does it make more sense now please?</p>