title: ggplot not working properly inside eventReactive() in shiny
body: <p>I wasted hours to find out why my plot is automatically updating itself when I change inputs while it was supposed to wait for the <strong>Run</strong> button but it simply ignored that step and I ended up finally finding <strong>ggplot</strong> as the trouble maker!!! This is my minimal code:</p>
  <pre><code>library(ggplot2)
  library(tidyverse)
  
  varnames &lt;- names(cars)
  
  ui &lt;- fluidPage(
    sidebarLayout(
      sidebarPanel(
        fluidRow(
          column(
            width = 12,
  
            # Variables Inputs:
            varSelectInput(&quot;variables&quot;, &quot;Select Input Variables&quot;, cars, multiple = TRUE),
            selectizeInput(&quot;outvar&quot;, &quot;Select Output Variable&quot;, choices = varnames, &quot;speed&quot;, multiple = F),
  
            # Run Button
            actionButton(inputId = &quot;run&quot;, label = &quot;Run&quot;)
          )
        )
      ),
  
      # Main panel for displaying outputs ----
      mainPanel(
        plotOutput(&quot;plot&quot;)
      )
    )
  )
  
  server &lt;- function(input, output, session) {
    
    df &lt;- reactive({
      cars %&gt;% dplyr::select(!!!input$variables, input$outvar)
    })
  
  
    plt &lt;- eventReactive(input$run, {
      
      #Just creating lm formula
      current_formula &lt;- paste0(input$outvar, &quot; ~ &quot;, paste0(input$variables, collapse = &quot; + &quot;))
      current_formula &lt;- as.formula(current_formula)
      #Fitting lm
      fit &lt;- lm(current_formula, data = df())
      pred &lt;- predict(fit, newdata = df())
  
      #Plotting
      ggplot(df(), aes(df()[, input$outvar], pred)) +
        labs(x = &quot;Observed&quot;, y = &quot;Predicted&quot;) +
        geom_point() +
        theme_bw()
  
       #plot(df()[, input$outvar], pred)       #This one works fine!!!!
    })
  
  
    output$plot &lt;- renderPlot({
       plt()
    })
  }
  
  # Run the application
  shinyApp(ui = ui, server = server)
  
  </code></pre>
  <p>If you run this, you'll notice that ggplot doesn't care anymore about the <strong>Run</strong> button after the 1st run and it keeps updating as you change the inputs!! However, if you use the simple base <strong>plot</strong> function (which I put in a comment in the code) there wouldn't be any problems and that works just fine! Sadly I need ggplot in my app because base plot is ugly. I am seeing suggestion for using isolate() to solve this issue but I have no clue where isolate() should be put to fix my problem also it doesn't make sense to use isolate() when base plot function works fine without it and it's the ggplot that makes the problem. Any explanation would be appreciated.</p>