if (interactive()) {
library(shiny)
#--- Example 1: Using showSpinner/hideSpinner ---
shinyApp(
ui = fluidPage(
actionButton("show", "Show"),
actionButton("hide", "Hide"),
withSpinner(plotOutput("plot"))
),
server = function(input, output) {
output$plot <- renderPlot({
plot(runif(10))
})
observeEvent(input$show, {
showSpinner("plot")
})
observeEvent(input$hide, {
hideSpinner("plot")
})
}
)
#--- Example 2: Using showSpinner with expr ---
some_slow_function <- function() {
Sys.sleep(2)
}
shinyApp(
ui = fluidPage(
actionButton("show", "Show"),
withSpinner(plotOutput("plot"))
),
server = function(input, output) {
output$plot <- renderPlot({
plot(runif(10))
})
observeEvent(input$show, {
showSpinner("plot", { some_slow_function() })
})
}
)
}
Run the code above in your browser using DataLab