Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a loading spinner on a map when updating with leafletProxy in Shiny

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?

like image 386
bwc Avatar asked Oct 29 '22 07:10

bwc


1 Answers

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).

like image 174
thmschk Avatar answered Nov 15 '22 07:11

thmschk