-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserver.R
97 lines (60 loc) · 2.76 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
library("shiny")
library("igraph")
source("deconvolve.R")
source("infosignature.R")
source("deconvolveterm.R")
source("scripts/loadGraph.R")
shinyServer(function(input, output, session) {
g <- load_graph("./data/testgraph.csv")
g_decomposed <- deconvolve_with_termination(g, 4, 4, 0.96)
react_graph <- reactiveValues(g = g, g_decomposed = g_decomposed)
observeEvent(input$param_adjustment, {
updateNumericInput(session, "param_adjustment")
})
observeEvent(input$file, {
if(is.null(input$file$datapath)) {}
else {react_graph$g <- load_graph(input$file$datapath)}
}, ignoreInit = FALSE)
output$graph_plot <- renderPlot({
plot(react_graph$g, edge.width = 2, edge.color = "Firebrick1",
vertex.color = "Lightblue2", vertex.size = 25,
vertex.label.family = "Arial Black")
})
output$graph2_plot <- renderPlot({
react_graph$g_decomposed <- deconvolve_with_termination(react_graph$g, 4, 4, input$param_adjustment)
plot(react_graph$g_decomposed, edge.width = 2, edge.color = "Firebrick1",
vertex.color = "Lightblue2", vertex.size = 25,
vertex.label.family = "Arial Black")
})
output$removed_edges <- renderText({
decomposed_df <- as_data_frame(react_graph$g %m%
react_graph$g_decomposed, what = "edges")
isolate({
if(nrow(decomposed_df) > 0) {
paste0(decomposed_df$from,"|",decomposed_df$to," ")
} else {
paste0(warning("No edges have been removed."))
}
})
})
output$info_signature <- renderPlot({
is <- get_info_signature(react_graph$g, 4, 4)
plot(log(is$information_loss)+80, xlab = "edges sorted by max info value",
ylab = "log info values (+80)", main = "Information signature", col = "red")
lines(log(is$information_loss)+80, col = "red")
})
output$cutting_points <- renderPlot({
is <- get_info_signature(react_graph$g, 4, 4)
diffs <- c()
for(i in 1:nrow(is)) {
if(i != nrow(is)) {
diffs <- c(diffs, is$information_loss[i]-is$information_loss[i+1])
}
}
plot(diffs, xlab = "edges sorted by max info value", ylab = "sequential info differences",
main = "Cutting points plot", col = "blue")
lines(diffs, col = "blue")
curve(log2(2)*x^0, col = "purple", add = TRUE)
legend("topright", "log(2)", lty = 1, col = "purple")
})
})