View source: R/withModalSpinner.R
withModalSpinner | R Documentation |
Display a modal window with a spinning wheel and an information message while a (time-consuming) expression is evaluated.
withModalSpinner(expr, info, spinner = shiny::icon("spinner", "fa-spin"),
size = "m")
expr |
The |
info |
The information message to be displayed. |
spinner |
The spinning wheel icon. |
size |
One of |
if (interactive()) {
library(shiny)
ui <- fluidPage(
titlePanel("withModalSpinner"),
actionButton("trigger_runif", "Trigger...", icon("cog")),
actionButton("trigger_expr", "Trigger...", icon("cog"))
)
slow_runif <- function(time) c(Sys.sleep(time), runif(1))
server <- function(input, output) {
observeEvent(input$trigger_runif, {
withModalSpinner(
message(slow_runif(2)),
"Waiting for a slow runif...",
size = "s"
)
})
observeEvent(input$trigger_expr, {
withModalSpinner(
{
Sys.sleep(1)
for (i in 1:10) {
message(i)
Sys.sleep(0.1)
}
},
"Waiting for a slow expression..."
)
})
}
# Run the application
runApp(shinyApp(ui = ui, server = server), launch.browser = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.