title: Disabling buttons in Shiny
body: <p>I am writing some Shiny code where the user will enter some inputs to the app and then click a an action button.  The action button triggers a bunch of simulations to run that take a long time so I want once the action button is clicked for it to be disabled so that the user can't keep clicking it until the simulations are run. I came across the <code>shinyjs::enable</code> and <code>shinyjs::disable</code> functions but have been having a hard time utilizing them.  Here is my server code:</p>
  
  <pre><code>output$button1= renderUI({
          if(input$Button1 &gt; 0)  {
            shinyjs::disable("Button1")
                  tableOutput("table")
            shinyjs::enable("Button1")}
    })
  </code></pre>
  
  <p>However, when I use this code, and click the action button nothing happens. I.e., teh action button doesn't grey out nor does the table get generated.  However, when I take away the <code>shinyjs::enable()</code> command, i.e., </p>
  
  <pre><code>    output$button1= renderUI({
              if(input$Button1 &gt; 0)  {
                shinyjs::disable("Button1")
                      tableOutput("table")
  }
        })
  </code></pre>
  
  <p>The table gets generated first, and then the button goes grey, however I would have expected the button to go grey and then the table to generate itself. </p>
  
  <p>What am I doing wrong here?</p>
  
  <hr>
  
  <p><strong>Here is my updated code based on Geovany's suggestion yet it still doesn't work for me</strong></p>
  
  <pre><code>Button1Ready &lt;- reactiveValues(ok = FALSE)
  
          observeEvent(input$Button1,  {
            shinyjs::disable("Button1")
            RunButton1Ready$ok &lt;- FALSE
            RunButton1Ready$ok &lt;- TRUE
    })
  
  output$SumUI1= renderUI({
          if(Button1Ready$ok){
            tableOutput("table")
            shinyjs::enable("Button1")
          }
  })
  </code></pre>
  
  <p>where for clarification I have also:</p>
  
  <pre><code>output$table &lt;- renderTable({
  
  #My code....
  
  )}
  </code></pre>