title: How to disable and enable reactivity in shiny modules?
body: <p>I'm trying to find a way to disable reactivity of the recently generated output but enable reactivity for the current output that is being rendered.</p>
  <p>In this example, I click <code>New</code> to start a new plot and choose inputs. Then, I click <code>New</code> again which creates a new plot below the first plot. However, when I change the inputs, all the output plots change. I only want the current new plot to change.</p>
  <p>To solve this issue I would like to click the <code>New</code> button which disables reactivity of the old plot but keeps reactivity enabled for the current new plot.</p>
  <pre><code>library(dplyr)
  library(rlang)
  library(ggplot2)
  
  scatter_plot &lt;- function(dataset, xvar, yvar) {
    
    x &lt;- rlang::sym(xvar)
    y &lt;- rlang::sym(yvar)
    
    p &lt;- ggplot(dataset, aes(x = !!x, y = !!y)) +
      geom_point() +
      theme(axis.title = element_text(size = rel(1.2)),
            axis.text = element_text(size = rel(1.1)))
    
    return(p)
    
  }
  
  
  regress &lt;- function(dataset, xvar, yvar) {
    
    # lefts &lt;- rlang::sym(xvar)
    # rights &lt;- rlang::sym(yvar)
    
    lefts &lt;- xvar
    rights &lt;- yvar
    
    lefts &lt;- paste(lefts, &quot; ~ &quot;)
    rights &lt;- paste(rights, collapse = &quot; + &quot;)
    
    formula &lt;- paste(lefts, rights)
    
    r &lt;- summary(lm(formula, data = dataset))
    
    return(r)
  }
  
  importUI &lt;- function(id) {
    ns &lt;- NS(id)
    
    tagList(
      fileInput(ns(&quot;file1&quot;), &quot;Choose CSV File&quot;, accept = &quot;.csv&quot;),
      checkboxInput(ns(&quot;header&quot;), &quot;Header&quot;, TRUE),
      #   tableOutput(ns(&quot;contents&quot;))
    )
    
  }
  
  importSE &lt;- function(id) {
    moduleServer(id,
                 function(input, output, session) {
                   
                   dtreact &lt;- reactive({
                     file &lt;- input$file1
                     if (is.null(file))
                       return(NULL)
                     read.csv(file$datapath, header = input$header)
                   })
                   
                   
                   output$contents &lt;- renderTable({
                     dtreact()
                   })
                   
                   return(dtreact)
                 }
    )
    
  }
  
  varselect_ui &lt;- function(id) {
    ns &lt;- NS(id)
    var_choices &lt;- &quot;&quot;
    tagList(selectInput(ns(&quot;xvar&quot;), &quot;Select X variable&quot;, choices = var_choices, selected = NULL),
            selectInput(ns(&quot;yvar&quot;), &quot;Select Y variable&quot;, choices = var_choices, selected = NULL))
  }
  
  varselect_server &lt;- function(id, dataset) {
    moduleServer(id,
                 function(input, output, session) {
                   observeEvent(dataset(), {
                     updateSelectInput(session,
                                       &quot;xvar&quot;,
                                       choices = names(dataset()))
                     updateSelectInput(session,
                                       &quot;yvar&quot;,
                                       choices = names(dataset()))
                   })
                   
                   return(
                     list(
                       xvar = reactive({input$xvar}),
                       yvar = reactive({input$yvar})
                     )
                   )
                 }
    )
  }
  
  regselect_ui &lt;- function(id) {
    ns &lt;- NS(id)
    var_choices &lt;- &quot;&quot;
    tagList(selectInput(ns(&quot;xvar&quot;), &quot;Select X variable&quot;, choices = var_choices, selected = NULL),
            selectInput(ns(&quot;yvar&quot;), &quot;Select Y variable&quot;, choices = var_choices, selected = NULL, multiple = TRUE))
  }
  
  regselect_server &lt;- function(id, dataset) {
    moduleServer(id,
                 function(input, output, session) {
                   observeEvent(dataset(), {
                     updateSelectInput(session,
                                       &quot;xvar&quot;,
                                       choices = names(dataset()))
                     updateSelectInput(session,
                                       &quot;yvar&quot;,
                                       choices = names(dataset()))
                   })
                   
                   return(
                     list(
                       xvar = reactive({input$xvar}),
                       yvar = reactive({input$yvar})
                     )
                   )
                 }
    )
  }
  scatterplot_ui &lt;- function(id) {
    ns &lt;- NS(id)
    plotOutput(ns(&quot;plot1&quot;))
    
  }
  
  scatterplot_server &lt;- function(id, dataset, xvar, yvar) {
    moduleServer(id,
                 function(input, output, session) {
                   
                   plot1_obj &lt;- reactive({
                     req(dataset())
                     p &lt;- scatter_plot(dataset(), xvar = xvar(), yvar = yvar())
                     return(p)
                   })
                   
                   output$plot1 &lt;- renderPlot({
                     plot1_obj()
                   })
                 }
    )
  }
  
  
  regressUI &lt;- function(id) {
    ns &lt;- NS(id)
    verbatimTextOutput(ns(&quot;regout&quot;))
  }
  
  
  regressSE &lt;- function(id, dataset, xvar, yvar) {
    moduleServer(id,
                 function(input, output, session) {
                   
                   reg_obj &lt;- reactive({
                     req(dataset())
                     r &lt;- regress(dataset(), xvar = xvar(), yvar = yvar())
                     return(r)
                   })
                   
                   output$regout &lt;- renderPrint({
                     reg_obj()
                   })
                 })
  }
  
  
  
  ui &lt;- fluidPage(
    wellPanel(selectInput(inputId = &quot;input1&quot;, label = NULL, choices = c(&quot; &quot;, &quot;Import&quot;, &quot;Select&quot;, &quot;Regress&quot;))),
    sidebarLayout(
      
      sidebarPanel(
        
        conditionalPanel(condition = &quot;input.input1 == 'Import'&quot;, importUI(&quot;import&quot;)),
        conditionalPanel(condition = &quot;input.input1 == 'Select'&quot;, actionButton(&quot;run1&quot;, &quot;New&quot;), varselect_ui(&quot;select&quot;)),
        conditionalPanel(condition = &quot;input.input1 == 'Regress'&quot;, actionButton(&quot;run2&quot;, &quot;New &quot;), regselect_ui(&quot;select1&quot;))),
      
      mainPanel(div(id = &quot;add_here&quot;))))
  
  
  server &lt;- function(input, output, session) {
    
    dataset &lt;- importSE(&quot;import&quot;)
    
    df &lt;- dataset
    
    plotvars &lt;- varselect_server(&quot;select&quot;, dataset = dataset)
    
    plotvars2 &lt;- regselect_server(&quot;select1&quot;, dataset = dataset)
    
    
    
    
    #  regressSE(&quot;regress1&quot;, dataset = df, xvar = plotvars2$xvar, yvar = plotvars2$yvar)
    
   #  output$contents &lt;- renderTable({
   #    dataset()
   #  })
    
    counter &lt;- 1
    
    observeEvent(input$run1, {
      current_id &lt;- paste0(&quot;out_&quot;, counter)
      
      scatterplot_server(id = current_id,
                     dataset = df, 
                     xvar = plotvars$xvar,
                     yvar = plotvars$yvar)
      
      
      insertUI(selector = &quot;#add_here&quot;, 
               ui = scatterplot_ui(current_id))
      
      
      counter &lt;&lt;- counter + 1
    })
    
    observeEvent(input$run2, {
      current_id &lt;- paste0(&quot;out_&quot;, counter)
      
      r &lt;- regressSE(id = current_id,
                     dataset = df, 
                     xvar = plotvars2$xvar,
                     yvar = plotvars2$yvar)
      
      output$out &lt;- renderPrint({
        r
      })
      
      insertUI(selector = &quot;#add_here&quot;, 
               ui = regressUI(current_id))
      
      
      counter &lt;&lt;- counter + 1
    })
    
  }
  
  shinyApp(ui, server)
  
  </code></pre>
  <p>As you can see, changing the input changes all the output. But I want only the second output to change based on the input.</p>
  <p><a href="https://i.stack.imgur.com/BTKmG.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BTKmG.gif" alt="enter image description here" /></a></p>