-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.R
70 lines (58 loc) · 1.74 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
shinyServer(function(input, output, session) {
react <- reactiveValues(count = 0)
observe({
input$reset
isolate({
pop <<- data.frame(x = runif(input$nIndiv, min = -1, max = 1),
y = runif(input$nIndiv, min = -1, max = 1),
h = runif(input$nIndiv, min = -pi, max = pi),
s = 0.01,
col = sample(c("#107AB6", "#D86810"), input$nIndiv, replace = TRUE))
})
react$count <- 0
})
locs <- reactive({
invalidateLater(60, NULL)
if (is.null(pop)) {
return()
}
if (run) {
isolate({
pop <<- sp(pop, input$affinSame, input$affinOther)
pop <<- rw(pop)
react$count <- react$count + 1
})
}
pop
})
observe({
if (input$start > 0) {
run <<- TRUE
}
})
observe({
if (input$stop > 0) {
run <<- FALSE
}
})
output$count <- renderText({
react$count
})
observe({
if (is.null(locs)) {
return()
}
locs %>%
ggvis(x = ~x, y = ~y) %>%
layer_points(fill := ~col) %>%
scale_numeric("x", domain = c(-1, 1)) %>%
scale_numeric("y", domain = c(-1, 1)) %>%
add_axis("x", title = "", properties = axis_props(labels = list(fontSize = 0))) %>%
add_axis("x", title = "", properties = axis_props(labels = list(fontSize = 0)), orient = "top") %>%
add_axis("y", title = "", properties = axis_props(labels = list(fontSize = 0))) %>%
add_axis("y", title = "", properties = axis_props(labels = list(fontSize = 0)), orient = "right") %>%
set_options(width = "auto", height = "100%", resizable = FALSE,
duration = 30) %>%
bind_shiny("display")
})
})