5

The 'shinycssloaders' package was developed as a simple wrapper to provide loading icons to UI output, which works great. Unfortunately, it does not work for maps that are updated via leafletProxy (only the initial map produced will use a loading icon).

Is there a known solution for this?

bwc
  • 1,028
  • 7
  • 18
  • 1
    I'm also using leafletProxy and this example works fine for me: https://github.com/AnalytixWare/ShinySky/blob/master/R/busy-indicator.r – thmschk Aug 09 '18 at 20:28
  • Which function do I wrap with busyIndicator()? – bwc Aug 09 '18 at 20:55
  • [shinycssloaders](https://github.com/andrewsali/shinycssloaders) – JohnCoene Aug 09 '18 at 22:26
  • John, he said shinycssloaders does not work when updating leaflet map object via leaflet::leafletProxy. I can confirm this behavior. – kraggle Sep 22 '22 at 14:22

1 Answers1

2

Here's how I use the function provided by github.com/AnalytixWare/ShinySky/blob/master/R/busy-indicator.r

In your UI:

 tagList(
    tags$head(
      tags$script(type="text/javascript", src = "busy.js")
    )
  ),
  div(class = "busy", p('your text'),img(src="loader.gif")
)

where a folder www inlcudes the loader.gif and busy.js with

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

The loader.gif (and the text if provided) then always appears when shiny is busy (with the delay provided in the function).

thmschk
  • 614
  • 3
  • 16
  • 1
    Does this work with leaflet though? Most solutions do not. – Simon Woodward Mar 23 '20 at 22:52
  • 1
    I'm not entirely sure (don't use leaflet anymore), but I think to remember that it was working fine. It just might happen that the loader doesn't show up when the map is rendered (after the data is loaded/calculated). In my case this wasn't a big drawback. – thmschk Mar 25 '20 at 22:32
  • How do I hide the loader gif? Can I show it and hide it manually. (It does show over leaflet render provided you make z-index position high enough). – Simon Woodward Mar 31 '20 at 23:23
  • well, the purpose of this function is to load the spinner whenever shiny is busy. If you want the spinner show and hide manually, I would suggest to show and hide the loader using observe with shinyjs::show and shinyjs::hide. Maybe you could provide a MWE, then I could try to provide an example. – thmschk Apr 01 '20 at 19:55