Disable the action button until the computation is finished?

826 views
Skip to first unread message

Arun

unread,
Feb 26, 2016, 2:26:29 AM2/26/16
to Shiny - Web Framework for R
I am in the process of automating a computationally intensive process and have used the progress bars to indicate the status of the job.

Still, users are mistakenly clicking on the "GO" button twice and the whole computation is starting again.

Is there any easy way to disable the "GO" action button until the computation is finished?

Thanks.

Joe Cheng

unread,
Feb 26, 2016, 2:30:19 AM2/26/16
to Arun, Shiny - Web Framework for R
Google for the shinyjs package, I'm pretty sure it can do that.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/1065eb48-276f-4809-98e5-5330d798493d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

luis.g...@gmail.com

unread,
Feb 26, 2016, 9:02:44 AM2/26/16
to Shiny - Web Framework for R
shinyjs has the toggleState which will do what you want. I've had the same problem before, and I've noticed that most users can't spot the progress bars on top of the screen, so I ended up using a combo of toggleState (for things that get loaded to initialize a given selectize) and using 'shiny-busy' with a spinning logo in a conditional panel in your ui file to tell users to chill and stop the clicky-clicky... :)

conditionalPanel(condition="$('html').hasClass('shiny-busy')",
                               absolutePanel(top="25%", left ="25%",
                                             wellPanel(style="background-color:green; color:white",
                                                       draggable = TRUE,icon("refresh fa-spin fa-2x", lib="font-awesome"),
                                                       "Loading..."
                                             )
                               )
              )

Lukasz Kiljanek

unread,
Feb 27, 2016, 6:13:37 PM2/27/16
to Shiny - Web Framework for R
Use shinyJS it is really easy.
First you catch the even with onevent when the button it is clicked (this has to go in front of all computations, into server.R file...)
observeEvent(input$Analyze,(
    {
  
     
      shinyjs::disable("Analyze")

..... computations go here.....


      shinyjs::enable("Analyze")
   {
))

life example is here dodxtx.com

Lukasz Kiljanek

unread,
Feb 27, 2016, 6:50:55 PM2/27/16
to Shiny - Web Framework for R
Sorry typos


Use shinyJS it is really easy.
First you catch the event with when the button is clicked (this has to go in front of all computations, into server.R file...)


observeEvent(input$Analyze,(
    {
  
     
      shinyjs::disable("Analyze")

..... computations go here.....


      shinyjs::enable("Analyze")
   }
))

life example is here dodxtx.com

Arun

unread,
Feb 27, 2016, 10:45:41 PM2/27/16
to Shiny - Web Framework for R
Thanks all for the reply.

Hi Lukasz,

I tried including it for a tabpanel as below in shiny.R. After reloading it, i still see that button is not disabled. Am i missing anything here?

Appreciate your help!

  rv <- reactiveValues(table = NULL)
    
    observeEvent(input$goButtona, {
      
      shinyjs::disable("goButtona")
      
      rv$table <- isolate({
        withProgress(message = "Pulling the exp", {
          
          
          updateDateInput(session,"dateb",value = input$datea)
          
          if (input$old_new_ind == TRUE)
            
          {
            inc(date1 = input$datea,threshold = input$threshold, date2 = input$datea -1)
            
          }
          
          else
            
          {
           inc(date1 = input$datea,threshold = input$threshold, date2 = input$datea -1)
          }
          
          
          
        })
        
      })
      
      shinyjs::enable("goButtona") 
      
    })

Arun

unread,
Feb 28, 2016, 12:24:33 AM2/28/16
to Shiny - Web Framework for R
It's working now after adding the shinyjs() in the ui and disable and enable options directly in the server.R


ui.R

library(shinyjs)

# Define UI for application that draws a histogram
shinyUI(fluidPage(theme = shinytheme("united"),
  useShinyjs(),
  wellPanel(fluidRow(
    column(5,h1("")),column(2,h2("EP Tools")),column(5,h1(""))
  )),

server.R

     disable("goButtona")
     
computation

     enable("goButtona")

Thanks.





Lukasz Kiljanek

unread,
Mar 21, 2016, 4:26:55 AM3/21/16
to Shiny - Web Framework for R
Yeah!
Sorry, didnt see the question until you got this right :) best
Reply all
Reply to author
Forward
0 new messages