Add 'calculation in process' busy indicator for application need long time.

2,639 views
Skip to first unread message

Huidong TIAN

unread,
Jan 3, 2014, 8:22:25 AM1/3/14
to shiny-...@googlegroups.com
Hi Shiny users,
  I would like to share my experience of adding a 'calculation in process' busy indicator for the application need long time to run. 
  
  Please take a look of my example: http://spark.rstudio.com/withr/busyIndictor/


Regards!

Huidong



Vincent Nijs

unread,
Jan 3, 2014, 2:23:34 PM1/3/14
to shiny-...@googlegroups.com
I have something similar based on this thread:


In my app I have something like:

      conditionalPanel(condition="$('html').hasClass('shiny-busy')",
        tags$img(src="loading_circle.gif")
      ), 
      conditionalPanel(condition="!$('html').hasClass('shiny-busy')",
        plotOutput("visualize")
      )

It is nice that in your setup the busy indicator can be visible in all tabs and pages. However, it will also popup briefly if the page takes less than, for example, one second to load. Is there a way to only show the busy-indicator after, say, one second if shiny-busy is still true?

Huidong TIAN

unread,
Jan 3, 2014, 5:34:11 PM1/3/14
to shiny-...@googlegroups.com
Hi Vincent,
  Yes, it's possiable and not difficult, just change the 'busy.js' to:

setInterval(function(){
  if ($('html').attr('class')=='shiny-busy') {
    setTimeout(function() {
      if ($('html').attr('class')=='shiny-busy') {
        $('div.busy').show()
      }
    }, 1000)
    
  } else {
    $('div.busy').hide()
  }
},100)


 Best!

Huidong

Vincent Nijs

unread,
Jan 3, 2014, 7:38:41 PM1/3/14
to shiny-...@googlegroups.com
Thanks Huidong

ZJ

unread,
Jan 4, 2014, 1:53:01 AM1/4/14
to shiny-...@googlegroups.com
Very useful. Thinking about incorporating it into shinysky. What license is the code under?

Huidong TIAN

unread,
Jan 4, 2014, 3:20:28 AM1/4/14
to shiny-...@googlegroups.com
Free, like other open source code.

ZJ

unread,
Jan 4, 2014, 3:52:44 AM1/4/14
to shiny-...@googlegroups.com
ok. The shinysky has been updated with a busyIndicator() function that implements your ideas.

Blake Arensdorf

unread,
Feb 3, 2014, 6:56:23 PM2/3/14
to shiny-...@googlegroups.com
Thank guys, this is great. However, I'm not seeing an explanation of how to actually get the busyindicator into my code. Where to I put it in server.R or ui.R?
Message has been deleted

Huidong TIAN

unread,
Feb 4, 2014, 2:38:40 AM2/4/14
to shiny-...@googlegroups.com
Hi, take a look of this gist: https://gist.github.com/withr/8799489

and run this code in your R console:
library(shiny)

Blake Arensdorf

unread,
Feb 4, 2014, 1:39:28 PM2/4/14
to shiny-...@googlegroups.com
Perfect, thanks.

Stéphane Laurent

unread,
Feb 4, 2014, 2:29:30 PM2/4/14
to shiny-...@googlegroups.com
Very nice.
But when going from a tab to another one, there is the same problem as https://groups.google.com/d/topic/shiny-discuss/ZfPCt0QqUuA/discussion

Vincent Nijs

unread,
Feb 5, 2014, 4:24:50 PM2/5/14
to shiny-...@googlegroups.com
Same thing happens in my app when changing tabs. Strange that shiny-busy doesn't get set then.

Huidong TIAN

unread,
Feb 5, 2014, 5:59:05 PM2/5/14
to shiny-...@googlegroups.com
Hi, could you give a gist link? That will save coding time.

Joe Cheng

unread,
Feb 5, 2014, 8:32:27 PM2/5/14
to Vincent Nijs, shiny-...@googlegroups.com
Thanks guys, I think I might know what is causing that.

Filed as issue #385: https://github.com/rstudio/shiny/issues/385


--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Huidong TIAN

unread,
Feb 6, 2014, 5:55:21 AM2/6/14
to shiny-...@googlegroups.com, Vincent Nijs
Hi, 
  I guess this is a bug of tabsetPanel. My reason is: the content of each tab should have been generated when the reactive value inside them was triggered, 
  so switch tabs should just to show and hide the tab's content, not re-generate them. It shouldn't be busy when switch tabs.

  I have little knowledge about the mechanism of shiny, but found a way to solve such problem, though not convenient. Please take a look of my gist:


Best!

Joe Cheng

unread,
Feb 6, 2014, 7:10:57 PM2/6/14
to Huidong TIAN, shiny-...@googlegroups.com, Vincent Nijs
It may be surprising but (if I understand you correctly) it's intended behavior. Switching tabs does just show and hide the tab's content, BUT, tabs that are not shown don't have their contents generated until they are shown. In other words, if a tab's output is invalidated while the tab is not shown, then that output will not be recalculated, not until the tab is shown. But once the tab is shown, then switching away from and back to that tab shouldn't cause any recalculation (unless, again, the output becomes invaliated in the meantime).

If you don't like this behavior, you can opt out of it on a per-output basis using the outputOptions function's suspendWhenHidden argument.

Vincent Nijs

unread,
Feb 6, 2014, 8:07:39 PM2/6/14
to shiny-...@googlegroups.com, Huidong TIAN, Vincent Nijs
But shiny-busy should still be set when switching to a tab for the first time correct?

Stéphane Laurent

unread,
Feb 7, 2014, 2:15:16 AM2/7/14
to shiny-...@googlegroups.com, Huidong TIAN, Vincent Nijs
Joe isn't it strange that my solution works ? (the one I gave recently in this discussion https://groups.google.com/forum/#!topic/shiny-discuss/ZfPCt0QqUuA)

Huma Shehwana

unread,
Jun 13, 2016, 9:59:24 AM6/13/16
to Shiny - Web Framework for R
Hi
I am facing the same problem i.e. frequent display of busy message. I wonder where do i have to change busy.je to code you provided?
Reply all
Reply to author
Forward
0 new messages