I'm building a Shiny gadget using miniUI. I would like to display a loading screen while the gadget does some prep work and have tried implementing this simple and convenient solution: https://github.com/daattali/advanced-shiny/blob/master/loading-screen/app.R
Here's a small example of what the gadget might look like:
library(shiny)
library(shinyjs)
library(miniUI)
sampleApp <- function() {
ui <- miniPage(
gadgetTitleBar("Sample App"),
miniTabstripPanel(
miniTabPanel(
"Panel 1",
fillCol(div("Content of Panel 1"))
),
miniTabPanel(
"Panel 2",
fillCol(div("Content of Panel 2"))
),
between = p("") # Needed later on to avoid error in shinyjs::hidden()
)
)
server <- function(input, output) {
}
runGadget(ui, server, viewer = dialogViewer("Sample dialog"))
}
sampleApp()
I have tried several ways of adapting the loading screen code to my example. I can't seem to get the content to hide:
Place hidden() around miniTabstripPanel():
library(shiny) library(shinyjs) library(miniUI) appCSS <- " #loading-content { position: absolute; background: #000000; opacity: 0.9; z-index: 100; left: 0; right: 0; height: 100%; text-align: center; color: #FFFFFF; } " sampleApp <- function() { ui <- miniPage( useShinyjs(), inlineCSS(appCSS), # Loading message div( id = "loading-content", h2("Loading...") ), # The main app code goes here gadgetTitleBar("AppTitle"), hidden( miniTabstripPanel( miniTabPanel( "Panel 1", fillCol(div("Content of Panel 1")) ), miniTabPanel( "Panel 2", fillCol(div("Content of Panel 2")) ), between = p("") # Needed later on to avoid error in shinyjs::hidden() ), id = "app-content" ) ) server <- function(input, output) { # Simulate work being done for 1 second Sys.sleep(1) # Hide the loading message when the rest of the server function has executed hide(id = "loading-content", anim = TRUE, animType = "fade") show("app-content") } runGadget(ui, server, viewer = dialogViewer("Sample dialog")) } sampleApp()
Wrap content in a div().
- Use a tagList() according to this answer https://stackoverflow.com/a/32386689/5664232