shinyshinyjs

R Shiny - initiate loading screen from global.R?


I have a Shiny app that uses a global.R file to load some large datasets, something that takes around 15-20 seconds.

When the app is loading, only a blank white screen is shown.

I'd like to be able to display some kind of "Loading.." message or animation. The problem is, in exploring options for this (like the Waiter package) is that I've only found solutions that work when the loading message process is initiated in the server code. By the time the global.R has run, the server code runs very fast so having a loading screen initiated there doesn't help any.

So I was wondering if something could be done to display any kind of loading message (even a line of plain text would be better than a blank screen) that can be initiated before the long-running processes in global.R occur. I know it's also an option to move the long-running stuff to the server code, but would like to avoid that if possible.


Solution

  • The solution is to move the code that loads the data into the server code. If global.R is run before the shiny server is started R can not communicate with the client browser. Until shiny is started there is just a plain R session with no webserver capabilities.