1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/show-hide.R
\name{showHide}
\alias{showHide}
\alias{showSpinner}
\alias{hideSpinner}
\title{Manually show/hide a spinner}
\usage{
showSpinner(id, expr)
hideSpinner(id)
}
\arguments{
\item{id}{The ID of the Shiny output. The corresponding output must have been
wrapped in \code{\link[=withSpinner]{withSpinner()}} in the UI.}
\item{expr}{(optional) An R expression to run while showing the spinner. The
spinner will automatically get hidden when this expression completes.}
}
\value{
If \code{expr} is provided, the result of \code{expr} is returned. Otherwise, \code{NULL}.
}
\description{
Any Shiny output that uses \code{\link[=withSpinner]{withSpinner()}} will automatically show a spinner
while it's recalculating. Use \code{\link[=showSpinner]{showSpinner()}} and \code{\link[=hideSpinner]{hideSpinner()}} to manually
trigger the spinner on-demand.
}
\examples{
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() })
})
}
)
}
}
\seealso{
\code{\link[=withSpinner]{withSpinner()}}
}
|