title: Using Shiny's updateSelectInput within nested modules
body: <h1>Background</h1>
  <p>The application is of the following structure:</p>
  <pre><code>.
  ├── R
  │   ├── mod_observationSelector.R
  │   ├── mod_previewTable.R
  │   └── mod_summaryTable.R
  └── app.R
  </code></pre>
  <p>With the files fulling the respective functions:</p>
  <ul>
  <li><code>mod_observationSelector.R</code> - provides an <code>updateSelectInput</code> mechanism facilitating selction of integere or real columns in <code>mtcars</code> data</li>
  <li><code>mod_previewTable.R</code> - generates <code>head</code> for selected column</li>
  <li><code>mod_summaryTable.R</code> - generates <code>summary</code> for selected column</li>
  </ul>
  <h2>Design assumptions</h2>
  <ul>
  <li><code>mod_observationSelector.R</code> linked interface elements available in this module should be usable across remaining modules providing a selection mechanism</li>
  </ul>
  <h1>Problem</h1>
  <p>After nesting, the drop-down selection does no longer update.</p>
  <h2>Working version</h2>
  <p><em>Prior to nesting.</em></p>
  <h3><code>mod_observationSelector.R</code></h3>
  <pre><code>observationSelectorUI &lt;- function(id) {
      ns &lt;- NS(id)
      fluidPage(
          selectInput(
              inputId = ns(&quot;varTypes&quot;),
              label = h3(&quot;Variable types&quot;),
              choices = list(&quot;Integer&quot; = TRUE,
                             &quot;Real&quot; = FALSE),
              selectize = FALSE,
              multiple = FALSE
          ),
  
          selectInput(
              inputId = ns(&quot;selectColumn&quot;),
              label = h4(&quot;Selected Column&quot;),
              choices = character(0)
          )
      )
  }
  
  observationSelectorServer &lt;- function(id, data) {
      moduleServer(id,
                   function(input, output, session) {
                       observeEvent(eventExpr = input$varTypes,
                                    handlerExpr = {
                                        all_cols &lt;- map_lgl(.x = mtcars, ~ all(. %% 1 == 0))
                                        selected_cols &lt;-
                                            names(all_cols[all_cols == input$varTypes])
                                        updateSelectInput(
                                            session = session,
                                            inputId = &quot;selectColumn&quot;,
                                            label = paste(
                                                &quot;Selected&quot;,
                                                ifelse(input$varTypes, &quot;integer&quot;, &quot;real&quot;),
                                                &quot;columns&quot;
                                            ),
                                            choices = selected_cols
                                        )
                                    })
                   })
  }
  </code></pre>
  <h3><code>app.R</code></h3>
  <pre><code>library(&quot;shiny&quot;)
  library(&quot;tidyverse&quot;)
  
  
   ui &lt;- fluidPage(
  
  
       titlePanel(&quot;Nested Modules&quot;),
       observationSelectorUI(&quot;colChooser&quot;)
   )
  
   # Define server logic required to draw a histogram
   server &lt;- function(input, output) {
       observationSelectorServer(&quot;colChooser&quot;)
   }
  
   # Run the application
   shinyApp(ui = ui, server = server)
  </code></pre>
  <h1>Broken version</h1>
  <h2>Problems</h2>
  <ol>
  <li>Previously working <code>updateSelect</code> is now broken</li>
  </ol>
  <h3><code>app.R</code></h3>
  <pre><code>library(&quot;shiny&quot;)
  library(&quot;tidyverse&quot;)
  
  
  ui &lt;- fluidPage(titlePanel(&quot;Nested Modules&quot;),
                  tabsetPanel(summaryUI(&quot;modSummary&quot;),
                              previewUI(&quot;modPreview&quot;)
                              ))
  
  # Define server logic required to draw a histogram
  server &lt;- function(input, output) {
      summaryServer(&quot;modSummary&quot;)
      previewServer(&quot;modPreview&quot;)
  }
  
  # Run the application
  shinyApp(ui = ui, server = server)
  </code></pre>
  <h3><code>mod_observationSelector.R</code></h3>
  <p>In effect, no change.</p>
  <pre><code>observationSelectorUI &lt;- function(id) {
      ns &lt;- NS(id)
      fluidPage(
          selectInput(
              inputId = ns(&quot;varTypes&quot;),
              label = h3(&quot;Variable types&quot;),
              choices = list(&quot;Integer&quot; = TRUE,
                             &quot;Real&quot; = FALSE),
              selectize = FALSE,
              multiple = FALSE
          ),
  
          selectInput(
              inputId = ns(&quot;selectColumn&quot;),
              label = h4(&quot;Selected Column&quot;),
              choices = character(0)
          )
      )
  }
  
  observationSelectorServer &lt;- function(id, data) {
      moduleServer(id,
                   function(input, output, session) {
                       observeEvent(eventExpr = input$varTypes,
                                    handlerExpr = {
                                        all_cols &lt;- map_lgl(.x = mtcars, ~ all(. %% 1 == 0))
                                        selected_cols &lt;-
                                            names(all_cols[all_cols == input$varTypes])
                                        updateSelectInput(
                                            session = session,
                                            inputId = &quot;selectColumn&quot;,
                                            label = paste(
                                                &quot;Selected&quot;,
                                                ifelse(input$varTypes, &quot;integer&quot;, &quot;real&quot;),
                                                &quot;columns&quot;
                                            ),
                                            choices = selected_cols
                                        )
                                    })
                   })
  }
  </code></pre>
  <h3><code>mod_summaryTable.R</code></h3>
  <pre><code>summaryUI &lt;- function(id) {
      ns &lt;- NS(id)
      tabPanel(&quot;Summary table&quot;,
               column(4, observationSelectorUI(ns(&quot;colChooser&quot;))),
               column(8, tableOutput(ns('summaryTable'))))
  }
  
  summaryServer &lt;- function(id) {
      moduleServer(id,
                   function(input, output, session) {
                       output$summaryTable &lt;-
                           renderTable(summary(mtcars[, input$selectColumn]))
                   })
  }
  </code></pre>
  <h3><code>mod_previewTable</code></h3>
  <pre><code>previewUI &lt;-     function(id) {
      ns &lt;- NS(id)
      tabPanel(&quot;Summary table&quot;,
               column(4, observationSelectorUI(ns(&quot;colChooser&quot;))),
               column(8, tableOutput(ns('headTable'))))
  }
  
  previewServer &lt;- function(id) {
      moduleServer(id,
                   function(input, output, session) {
                       output$headTable &lt;-
                           renderTable(head(mtcars[, input$selectColumn]))
                   })
  }
  </code></pre>
  <h1>Desired outcomes</h1>
  <ul>
  <li>Drop-down selection updates across the modules</li>
  <li>Results from the in-module drop-down selection can be used in &quot;outer&quot; module to produce summaries, etc.</li>
  </ul>
  <hr />
  <p><em>For convenience, the code is also available on GitHub: <a href="https://github.com/konradzdeb/nestedModule" rel="nofollow noreferrer">konradzdeb/nestedModule</a>.</em></p>