-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathshinybusy.Rmd
180 lines (117 loc) · 3.76 KB
/
shinybusy.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
title: "Busy indicator for shiny apps"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{shinybusy-usage}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
<style>
p > img {
width: 750px;
margin: 1em auto;
}
</style>
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(shinybusy)
```
{shinybusy} allow to add **global** indicators to a {shiny} application to show the user that application is busy (something is happening server-side). There is three main type of indicators :
* automatic, just add a line in UI, the indicator will show up whenever server is busy.
* manual, activate the indicator from the server when you want it to be displayed.
* modal indicators, display a modal and prevent user to interact with the application.
## Automatic indicators
The indicator will be displayed each time a calculation take more than the timeout defined (default to 1000ms), you don't have to intervene in the server.
Three indicators are available :
* a spinner : with `add_busy_spinner()`.
```{r, eval=FALSE}
# Add in UI
add_busy_spinner(spin = "fading-circle")
```
```{r, echo=FALSE}
knitr::include_graphics(path = "figures/add_busy_spinner.png")
```
* a top progress bar : with `add_busy_bar()`.
```{r, eval=FALSE}
add_busy_bar(color = "red", height = "8px")
```
```{r, echo=FALSE}
knitr::include_graphics(path = "figures/add_busy_bar.png")
```
* a GIF that will animate when app is busy : with : `add_busy_gif()`.
```{r, eval=FALSE}
# Add in UI
add_busy_gif(
src = "https://jeroen.github.io/images/banana.gif",
height = 70, width = 70
)
```
```{r, echo=FALSE}
knitr::include_graphics(path = "figures/add_busy_gif.png")
```
## Manual indicators
The same types of indicators are available than for automatic indicators, but this time functions starts with `use_*` and you have to explicitly trigger the indicator server-side.
* spinner : with `use_busy_spinner()` :
```{r, eval=FALSE}
# in UI
use_busy_spinner(spin = "fading-circle")
# in server
show_spinner() # show the spinner
hide_spinner() # hide the spinner
```
* top progress bar : with `use_busy_bar()` :
```{r, eval=FALSE}
# in UI
use_busy_bar(color = "#01DF01", height = "15px")
# in server
update_busy_bar(0) # update with the desire value [0-100], 100 hide the bar
```
* GIF : with `use_busy_gif()` :
```{r, eval=FALSE}
# in UI
use_busy_gif(
src = "https://jeroen.github.io/images/banana.gif",
height = 70, width = 70
)
# in server
play_gif() # play animation
stop_gif() # stop animation
```
## Modal indicators
Display an indicator (a spinner or a progress bar) in a modal window, this prevent user to interact with the app and launch other calculation when something is already happening in the server. Those functions are only used server-side.
* Spinner :
```{r, eval=FALSE}
# in server
show_modal_spinner() # show the modal window
remove_modal_spinner() # remove it when done
```
```{r, echo=FALSE}
knitr::include_graphics(path = "figures/modal_spinner.png")
```
* Progress bar :
```{r, eval=FALSE}
# in server
show_modal_progress_line() # show the modal window
update_modal_progress(0.2) # update progress bar value
remove_modal_progress() # remove it when done
```
```{r, echo=FALSE}
knitr::include_graphics(path = "figures/modal_progress.png")
```
Don't forget to remove the modal window when computation is finished !
## Notifications
Show notifications and reports to user through JavaScript library [Notiflix](https://notiflix.github.io/). Four appearance are available: success, failure, info and warning. Notifications are fully configurable.
```{r notifications, eval=FALSE}
# success notification
notify_success("Well done!")
# report failure
report_failure(
"Oups...",
"Something went wrong"
)
```