-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
README.Rmd
151 lines (106 loc) · 3.76 KB
/
README.Rmd
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<div align="center">
<img src="./man/figures/logo.png" height = "200px" />
Loading screens for Shiny
<!-- badges: start -->
![R-CMD-check](https://github.com/JohnCoene/waiter/workflows/R-CMD-check/badge.svg)
[![CRAN status](https://www.r-pkg.org/badges/version/waiter)](https://CRAN.R-project.org/package=waiter)
<!-- badges: end -->
[Website](https://waiter.john-coene.com) | [Demo](https://shiny.john-coene.com/waiter/) | [Get Started](https://waiter.john-coene.com/#/waiter/intro) | [Cheat Sheet](https://waiter.john-coene.com/#/cheatsheet)
</div>
The waiter lets you programmatically show and hide partial or full page loading screens with spinners or loading bars to keep your users patiently waiting as you load or compute fancy things.
```{r, echo=FALSE, eval=TRUE}
yes <- ":heavy_check_mark:"
no <- ":heavy_multiplication_x:"
feat <- tibble::tribble(
~"Feature", ~"Waiter", ~"Waitress", ~"Hostess", ~"Attendant",
"Progress Bar", yes, yes, yes, yes,
"Full Screen", yes, yes, no, no,
"Works with waiter", yes, no, yes, yes,
"Spinner", yes, no, no, no,
"Updatable", yes, no, no, yes,
"Notifications", no, yes, no, no
)
knitr::kable(feat, align = "c")
```
## Examples
Below are simple examples of applications that use the package, consult the [website](https://waiter.john-coene.com) for more.
## Waiter
To use the waiter:
1. Include `useWaiter` in your UI.
2. Trigger `waiter_show` to show the waiting screen.
3. Eventually trigger `waiter_hide` to hide the loading screen.
```r
library(shiny)
library(waiter)
ui <- fluidPage(
useWaiter(), # include dependencies
actionButton("show", "Show loading for 3 seconds")
)
server <- function(input, output, session){
observeEvent(input$show, {
waiter_show( # show the waiter
html = spin_fading_circles() # use a spinner
)
Sys.sleep(3) # do something that takes time
waiter_hide() # hide the waiter
})
}
shinyApp(ui, server)
```
![](man/figures//waiter-basic.gif)
The waiter includes more options to customise the spinner, the background, show the waiter on load, etc.
### Waitress
To use the waitress:
1. Include `use_waitress` in your UI.
2. Initialise a waitress from the `Waitress` object with the `new` method.
3. You must then call the `start`.
4. On the waitress object use the `increase` method to increase the progress bar.
5. Use the `hide` method when done.
```r
library(shiny)
library(waiter)
ui <- fluidPage(
useWaitress(),
p("App content")
)
server <- function(input, output){
# call the waitress
waitress <- Waitress$
new(theme = "overlay-percent")$
start() # start
for(i in 1:10){
waitress$inc(10) # increase by 10%
Sys.sleep(.3)
}
# hide when it's done
waitress$close()
}
shinyApp(ui, server)
```
![](man/figures//waitress-basic.gif)
There are more options to the waitress, you can have it overlay any element (such as the navbar), automagically increment it, etc.
## Get it
You can install waiter from [CRAN](https://CRAN.R-project.org/package=waiter).
```r
install.packages("waiter")
```
Or the development version from Github with:
``` r
install.packages("remotes")
remotes::install_github("JohnCoene/waiter")
```
Please note that the 'waiter' project is released with a [Contributor Code of Conduct](https://waiter.john-coene.com/#/coc). By contributing to this project, you agree to abide by its terms.