% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/addSpinner.R
\name{addSpinner}
\alias{addSpinner}
\title{Display a spinner above an output when this one recalculate}
\usage{
addSpinner(output, spin = "double-bounce", color = "#112446")
}
\arguments{
\item{output}{An output element, typically the result of \code{renderPlot}.}

\item{spin}{Style of the spinner, choice between : \code{circle}, \code{bounce}, \code{folding-cube},
\code{rotating-plane}, \code{cube-grid}, \code{fading-circle}, \code{double-bounce}, \code{dots}, \code{cube}.}

\item{color}{Color for the spinner.}
}
\value{
a list of tags
}
\description{
Display a spinner above an output when this one recalculate
}
\note{
The spinner don't disappear from the page, it's only masked by the plot,
so the plot must have a non-transparent background. For a more robust way to
insert loaders, see package "shinycssloaders".
}
\examples{
# wrap an output:
addSpinner(shiny::plotOutput("plot"))

# Complete demo:

if (interactive()) {

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h2("Exemple spinners"),
  actionButton(inputId = "refresh", label = "Refresh", width = "100\%"),
  fluidRow(
    column(
      width = 5, offset = 1,
      addSpinner(plotOutput("plot1"), spin = "circle", color = "#E41A1C"),
      addSpinner(plotOutput("plot3"), spin = "bounce", color = "#377EB8"),
      addSpinner(plotOutput("plot5"), spin = "folding-cube", color = "#4DAF4A"),
      addSpinner(plotOutput("plot7"), spin = "rotating-plane", color = "#984EA3"),
      addSpinner(plotOutput("plot9"), spin = "cube-grid", color = "#FF7F00")
    ),
    column(
      width = 5,
      addSpinner(plotOutput("plot2"), spin = "fading-circle", color = "#FFFF33"),
      addSpinner(plotOutput("plot4"), spin = "double-bounce", color = "#A65628"),
      addSpinner(plotOutput("plot6"), spin = "dots", color = "#F781BF"),
      addSpinner(plotOutput("plot8"), spin = "cube", color = "#999999")
    )
  ),
  actionButton(inputId = "refresh2", label = "Refresh", width = "100\%")
)

server <- function(input, output, session) {

  dat <- reactive({
    input$refresh
    input$refresh2
    Sys.sleep(3)
    Sys.time()
  })

  lapply(
    X = seq_len(9),
    FUN = function(i) {
      output[[paste0("plot", i)]] <- renderPlot({
        dat()
        plot(sin, -pi, i*pi)
      })
    }
  )

}

shinyApp(ui, server)

}

}
