title: Generate progress bar in modal in shiny app, that closes automatically
body: <p>I am working on a shiny app that takes a long time to do calculations, I want to have a modal progress bar that closes automatically as soon as all calculations work.</p>
  
  <p>The ideal solution would have two features</p>
  
  <ol>
  <li>Covers most of the screen and prevents the user to interact with app</li>
  <li>Closes automatically as soon as it finishes making calulations</li>
  </ol>
  
  <p>I found this solution in the following question:</p>
  
  <pre><code>library("shiny")
  library("shinyWidgets")
  
  ui &lt;- fluidPage(
    actionButton(inputId = "go", label = "Launch long calculation"), #, onclick = "$('#my-modal').modal().focus();"
  
    # You can open the modal server-side, you have to put this in the ui :
    tags$script("Shiny.addCustomMessageHandler('launch-modal', function(d) {$('#' + d).modal().focus();})"),
    tags$script("Shiny.addCustomMessageHandler('remove-modal', function(d) {$('#' + d).modal('hide');})"),
  
    # Code for creating a modal
    tags$div(
  id = "my-modal",
  class="modal fade", tabindex="-1", `data-backdrop`="static", `data-keyboard`="false",
  tags$div(
    class="modal-dialog",
    tags$div(
      class = "modal-content",
      tags$div(class="modal-header", tags$h4(class="modal-title", "Calculation in progress")),
      tags$div(
        class="modal-body",
        shinyWidgets::progressBar(id = "pb", value = 0, display_pct = TRUE)
      ),
      tags$div(class="modal-footer", tags$button(type="button", class="btn btn-default", `data-dismiss`="modal", "Dismiss"))
    )
  )
    )
  )
  
  server &lt;- function(input, output, session) {
  
     value &lt;- reactiveVal(0)
  
    observeEvent(input$go, {
      shinyWidgets::updateProgressBar(session = session, id = "pb", value = 0) # reinitialize to 0 if you run the calculation several times
  session$sendCustomMessage(type = 'launch-modal', "my-modal") # launch the modal
      # run calculation
      for (i in 1:10) {
        Sys.sleep(0.5)
        newValue &lt;- value() + 1
        value(newValue)
        shinyWidgets::updateProgressBar(session = session, id = "pb", value = 100/10*i)
  }
      Sys.sleep(0.5)
      # session$sendCustomMessage(type = 'remove-modal', "my-modal") # hide the modal programmatically
    })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>This solves issue 1, but I have to click on dismiss to see the results</p>