-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspinkit-handler.R
94 lines (89 loc) · 2.57 KB
/
spinkit-handler.R
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#' SpinKit
#'
#' Simple CSS spinners.
#'
#' @param uiOutput An output element to be wrapped within a spinner.
#' @param type Type of spinner to use. Valid values are:
#' \itemize{
#' \item plane
#' \item chase
#' \item bounce
#' \item wave
#' \item pulse
#' \item flow
#' \item swing
#' \item circle
#' \item circle-fade
#' \item grid
#' \item fold
#' \item wander
#' }
#' @param color Color of the spinner. Defaults to \code{"#333"}. Choose between hexadecimal, RGB or keyword values.
#' @param size Size of the spinner. Defaults to \code{"40px"}.
#'
#' @section Functions:
#' \itemize{
#' \item \code{useSpinkit}: Dependencies to include in your UI.
#' \item \code{spinkit}: Display loading animation.
#' }
#'
#' @examples
#' if (interactive()) {
#' library(shiny)
#'
#' shinyApp(
#' ui = fluidPage(
#' useSpinkit(),
#' actionButton("render", "Render"),
#' spinkit(plotOutput("plot"), type = "circle-fade")
#' ),
#' server = function(input, output) {
#' output$plot <- renderPlot({
#' input$render
#' Sys.sleep(3)
#' hist(mtcars$mpg)
#' })
#' }
#' )
#' }
#'
#' @name spinkit
#' @return None
#'
#' @export
#'
spinkit <- function(uiOutput, type = "plane", color = "#333", size = "40px") {
base <- switch(type,
"plane" = spinkit_plane(color, size),
"chase" = spinkit_chase(size),
"bounce" = spinkit_bounce(color, size),
"wave" = spinkit_wave(color, size),
"pulse" = spinkit_pulse(color, size),
"flow" = spinkit_flow(color, size),
"swing" = spinkit_swing(color, size),
"circle" = spinkit_circle(size),
"circle-fade" = spinkit_circle_fade(size),
"grid" = spinkit_grid(color, size),
"fold" = spinkit_fold(size),
"wander" = spinkit_wander(color, size))
spin_css <- switch(type,
"chase" = paste0(".sk-chase-dot:before {background-color: ", color, ";}"),
"circle" = paste0(".sk-circle-dot:before {background-color: ", color, ";}"),
"circle-fade" = paste0(".sk-circle-fade-dot:before {background-color: ", color, ";}"),
"fold" = paste0(".sk-fold-cube:before {background-color: ", color, ";}"),
NULL)
shiny::tagList(
tags$head(
tags$style(
HTML(
spin_css
)
)
),
tags$div(
class = "standby",
base,
uiOutput
)
)
}