-
Notifications
You must be signed in to change notification settings - Fork 1
/
_server.R
109 lines (71 loc) · 2.03 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
message('|-- server')
Server <- shiny::shinyServer(function(input, output, session) {
# initialize variables
old.nodes = old.edges = NULL
# system time
log.file <- str_c('logs/record_', format(Sys.time(), "%d-%m-%y"), '.txt')
# output
output$network_proxy <- renderVisNetwork({
map <- Crawl(origin, depth, direction, type, private = NULL, up.initial, pop)
PlotGraph(map$objects, map$arrows, map$origin)
})
# observe
build <- observe({
# listener
input$buildGraph
isolate(if(input$direction == 'down') {
direction = 1
} else if(isolate(input$direction) == 'down & up') {
direction = 0
} else {
direction = -1
})
isolate(if(input$private == 'yes' & input$type == 'all') {
private = token
} else {
private = NULL
})
isolate(if(isolate(input$up.initial) == 'yes') {
up.initial = 1
} else {
up.initial = 0
})
depth <- isolate(as.numeric(input$depth))
isolate(if(input$buildGraph) {
map <- isolate(Crawl(input$origin, depth, direction, input$type, private, up.initial, input$pop))
visNetworkProxy('network_proxy') %>%
visUpdateNodes(map$objects %>% unique) %>%
visUpdateEdges(map$arrows %>% unique) %>%
visLayout(improvedLayout = TRUE)
})
visNetworkProxy("network_proxy") %>%
visGetEdges()
visNetworkProxy("network_proxy") %>%
visGetNodes()
isolate(cat(input$origin, '\n', file = log.file, append = TRUE))
})
clear <- observe({
input$clearGraph
isolate(if(input$clearGraph) {
if(!is.null(input$network_proxy_edges) & !is.null(input$network_proxy_nodes)) {
old.edges <-
input$network_proxy_edges %>%
map(~ { dplyr::as_data_frame(rbind(unlist(.x))) }) %>%
bind_rows
old.nodes <-
input$network_proxy_nodes %>%
map(~ { dplyr::as_data_frame(rbind(unlist(.x))) }) %>%
bind_rows
visNetworkProxy('network_proxy') %>%
visRemoveNodes(old.nodes$id) %>%
visRemoveEdges(old.edges$id)
}
})
})
# cleanup
session$onSessionEnded(function() {
build$suspend()
clear$suspend()
unlink(log.file)
})
})