| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/busy-indicators.R |
| 3 |
\name{busyIndicatorOptions} |
| 4 |
\alias{busyIndicatorOptions} |
| 5 |
\title{Customize busy indicator options} |
| 6 |
\usage{ |
| 7 |
busyIndicatorOptions( |
| 8 |
..., |
| 9 |
spinner_type = NULL, |
| 10 |
spinner_color = NULL, |
| 11 |
spinner_size = NULL, |
| 12 |
spinner_delay = NULL, |
| 13 |
spinner_selector = NULL, |
| 14 |
fade_opacity = NULL, |
| 15 |
fade_selector = NULL, |
| 16 |
pulse_background = NULL, |
| 17 |
pulse_height = NULL, |
| 18 |
pulse_speed = NULL |
| 19 |
) |
| 20 |
} |
| 21 |
\arguments{ |
| 22 |
\item{...}{Currently ignored.} |
| 23 |
|
| 24 |
\item{spinner_type}{The type of spinner. Pre-bundled types include: |
| 25 |
'ring', 'ring2', 'ring3', 'bars', 'bars2', 'bars3', 'pulse', 'pulse2', 'pulse3', 'dots', 'dots2', 'dots3'. |
| 26 |
|
| 27 |
A path to a local SVG file can also be provided. The SVG should adhere to |
| 28 |
the following rules: |
| 29 |
\itemize{ |
| 30 |
\item The SVG itself should contain the animation. |
| 31 |
\item It should avoid absolute sizes (the spinner's containing DOM element |
| 32 |
size is set in CSS by \code{spinner_size}, so it should fill that container). |
| 33 |
\item It should avoid setting absolute colors (the spinner's containing DOM element |
| 34 |
color is set in CSS by \code{spinner_color}, so it should inherit that color). |
| 35 |
}} |
| 36 |
|
| 37 |
\item{spinner_color}{The color of the spinner. This can be any valid CSS |
| 38 |
color. Defaults to the app's "primary" color if Bootstrap is on the page.} |
| 39 |
|
| 40 |
\item{spinner_size}{The size of the spinner. This can be any valid CSS size.} |
| 41 |
|
| 42 |
\item{spinner_delay}{The amount of time to wait before showing the spinner. |
| 43 |
This can be any valid CSS time and can be useful for not showing the spinner |
| 44 |
if the computation finishes quickly.} |
| 45 |
|
| 46 |
\item{spinner_selector}{A character string containing a CSS selector for |
| 47 |
scoping the spinner customization. The default (\code{NULL}) will apply the |
| 48 |
spinner customization to the parent element of the spinner.} |
| 49 |
|
| 50 |
\item{fade_opacity}{The opacity (a number between 0 and 1) for recalculating |
| 51 |
output. Set to 1 to "disable" the fade.} |
| 52 |
|
| 53 |
\item{fade_selector}{A character string containing a CSS selector for |
| 54 |
scoping the spinner customization. The default (\code{NULL}) will apply the |
| 55 |
spinner customization to the parent element of the spinner.} |
| 56 |
|
| 57 |
\item{pulse_background}{A CSS background definition for the pulse. The |
| 58 |
default uses a |
| 59 |
\href{https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient}{linear-gradient} |
| 60 |
of the theme's indigo, purple, and pink colors.} |
| 61 |
|
| 62 |
\item{pulse_height}{The height of the pulsing banner. This can be any valid |
| 63 |
CSS size.} |
| 64 |
|
| 65 |
\item{pulse_speed}{The speed of the pulsing banner. This can be any valid CSS |
| 66 |
time.} |
| 67 |
} |
| 68 |
\description{ |
| 69 |
Shiny automatically includes busy indicators, which more specifically means: |
| 70 |
\enumerate{ |
| 71 |
\item Calculating/recalculating outputs have a spinner overlay. |
| 72 |
\item Outputs fade out/in when recalculating. |
| 73 |
\item When no outputs are calculating/recalculating, but Shiny is busy |
| 74 |
doing something else (e.g., a download, side-effect, etc), a page-level |
| 75 |
pulsing banner is shown. |
| 76 |
} |
| 77 |
|
| 78 |
This function allows you to customize the appearance of these busy indicators |
| 79 |
by including the result of this function inside the app's UI. Note that, |
| 80 |
unless \code{spinner_selector} (or \code{fade_selector}) is specified, the spinner/fade |
| 81 |
customization applies to the parent element. If the customization should |
| 82 |
instead apply to the entire page, set \code{spinner_selector = 'html'} and |
| 83 |
\code{fade_selector = 'html'}. |
| 84 |
} |
| 85 |
\examples{ |
| 86 |
\dontshow{if (rlang::is_interactive()) withAutoprint(\{ # examplesIf} |
| 87 |
|
| 88 |
library(bslib) |
| 89 |
|
| 90 |
card_ui <- function(id, spinner_type = id) { |
| 91 |
card( |
| 92 |
busyIndicatorOptions(spinner_type = spinner_type), |
| 93 |
card_header(paste("Spinner:", spinner_type)), |
| 94 |
plotOutput(shiny::NS(id, "plot")) |
| 95 |
) |
| 96 |
} |
| 97 |
|
| 98 |
card_server <- function(id, simulate = reactive()) { |
| 99 |
moduleServer( |
| 100 |
id = id, |
| 101 |
function(input, output, session) { |
| 102 |
output$plot <- renderPlot({ |
| 103 |
Sys.sleep(1) |
| 104 |
simulate() |
| 105 |
plot(x = rnorm(100), y = rnorm(100)) |
| 106 |
}) |
| 107 |
} |
| 108 |
) |
| 109 |
} |
| 110 |
|
| 111 |
ui <- page_fillable( |
| 112 |
useBusyIndicators(), |
| 113 |
input_task_button("simulate", "Simulate", icon = icon("refresh")), |
| 114 |
layout_columns( |
| 115 |
card_ui("ring"), |
| 116 |
card_ui("bars"), |
| 117 |
card_ui("dots"), |
| 118 |
card_ui("pulse"), |
| 119 |
col_widths = 6 |
| 120 |
) |
| 121 |
) |
| 122 |
|
| 123 |
server <- function(input, output, session) { |
| 124 |
simulate <- reactive(input$simulate) |
| 125 |
card_server("ring", simulate) |
| 126 |
card_server("bars", simulate) |
| 127 |
card_server("dots", simulate) |
| 128 |
card_server("pulse", simulate) |
| 129 |
} |
| 130 |
|
| 131 |
shinyApp(ui, server) |
| 132 |
\dontshow{\}) # examplesIf} |
| 133 |
} |
| 134 |
\seealso{ |
| 135 |
\code{\link[=useBusyIndicators]{useBusyIndicators()}} to disable/enable busy indicators. |
| 136 |
} |