0

Hi I am writing a shiny app and on the server side code, I am calling a function when a user clicks the Run button. The issue I have is that the function takes around 10-25 minutes to run and a user might click the button multiple times during this period. After the function run is over, I show user the output path where the files have been downloaded and close the App. How can I prevent user from clicking the button multiple times, like a loading screen while the function is running?

observeEvent(input$runprocess, {
    rundownload()
    showModal(modalDialog(title ="Output folder: XYZ path",
                      actionButton("close", "Exit"),footer = NULL,
                      size = c("m"), easyClose = FALSE))
})

observeEvent(input$close, {
  js$closeWindow()
  stopApp()
}) 
Jain
  • 959
  • 2
  • 13
  • 31
  • By adding a modalDialog before you call `rundownload()`? – Joris Meys Jun 15 '17 at 14:27
  • @JorisMeys How will the user then know that the download has finished? – Jain Jun 15 '17 at 14:51
  • because after the download has finished, you have a second modalDialog telling it has finished. I didn't say "remove the other one" ;-) – Joris Meys Jun 15 '17 at 14:53
  • Now I realized I've seen that question before, so check the one I marked for some more variations on the same theme. But the general rule is you call any kind of code generating a loading message or whatever **before** you call the `rundownload()` in the same expression (i.e. the same `observe()` or `observeEvent()` call ) – Joris Meys Jun 15 '17 at 15:02

1 Answers1

0

By adding an extra modalDialog like this:

observeEvent(input$runprocess, {
    showModal(modalDialog(p("Start downloading. This might take a while"),
                         title = "download started",
              #etc etc
              ))
    rundownload()
    showModal(modalDialog(title ="Output folder: XYZ path",
                      actionButton("close", "Exit"),footer = NULL,
                      size = c("m"), easyClose = FALSE))
})

observeEvent(input$close, {
  js$closeWindow()
  stopApp()
}) 

And to prevent the user from clicking the Run button multiple times, you can use shinyjs to hide it after it has been clicked. See eg: Hide shiny output

Joris Meys
  • 106,551
  • 31
  • 221
  • 263