-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.R
114 lines (84 loc) · 2.43 KB
/
server.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
library(ggplot2)
library(gganimate)
library(ggforce)
library(glue)
library(waiter)
server = function(input, output, session){
Sys.sleep(2)
waiter_hide()
observeEvent(input$go_to_work, {
updateNavbarPage(session = session, "navbar", "Work")
})
## initialize loading screen for anim1
w1 = Waiter$new(
id = "anim1",
html = tagList(
div(
spin_loaders(42, color = "#aaa"),
div("Loading...",style = "color:#aaa;")
)),
color = "#272b30"
)
## intialize loading screen for anim2
w2 = Waiter$new(
id = "anim2",
html = tagList(
div(
spin_loaders(42, color = "#aaa"),
div("Loading...", align = "left", style = "color:#aaa;")
)),
color = "#272b30"
)
observeEvent(input$run, {
n = input$n
d1 = the_data(n)
disable(id = "run")
output$anim1 = renderImage({
w1$show() # show the waiter screen
if(n %in% pre_rendered) {
filename <- normalizePath(
file.path('./anims2', glue("anim1_{n}.gif")) # get a pre-rendered image
)
Sys.sleep(2) # to show the loading bar
w1$hide() # hide the waiter screen
list(src = filename,
contentType = 'image/gif'
)
}
else{
anim1 = make_anim1(d1) # make the animation
outfile <- tempfile(fileext='.gif')
save_animation(anim1, outfile)
w1$hide()
list(src = outfile,
contentType = 'image/gif'
)
}
}, deleteFile = FALSE)
##############################################
output$anim2 = renderImage({
w2$show()
if(n %in% pre_rendered) {
filename <- normalizePath(
file.path('./anims2', glue("anim2_{n}.gif"))
)
Sys.sleep(2)
w2$hide()
delay(12000, enable("run")) # enable the action button when animation is done
list(src = filename,
contentType = 'image/gif'
)
}
else {
anim2 = make_anim2(d1)
outfile <- tempfile(fileext='.gif')
save_animation(anim2, outfile)
w2$hide()
delay(10000, enable("run")) # enable the action button when animation is done
list(src = outfile,
contentType = 'image/gif'
)
}
}, deleteFile = FALSE)
})
}