-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.R
174 lines (130 loc) · 5.1 KB
/
app.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
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
# Library installs
# NOTE: To work properly you may need to remove.packages(thepackage), restart R, and install from source as shown.
if (!require("httpuv")) {
install.packages("https://cran.r-project.org/src/contrib/httpuv_1.5.1.tar.gz", repo=NULL, type="source")
library(httpuv)
}
if (!require("shiny")) {
install.packages("https://cran.r-project.org/src/contrib/shiny_1.3.2.tar.gz", repo=NULL, type="source")
library(shiny)
}
if (!require("mwshiny")) {
install.packages("https://cran.r-project.org/src/contrib/mwshiny_2.0.0.tar.gz", repo=NULL, type="source")
library(mwshiny)
}
if (!require("devtools")) {
install.packages("devtools")
library(devtools)
}
if (!require("visNetwork")) {
devtools::install_git("https://github.com/datastorm-open/visNetwork")
library(tidyverse)
}
if (!require("readr")) {
install.packages("readr", dependencies = TRUE)
library(readr)
}
if (!require("htmlwidgets")) {
install.packages("htmlwidgets", dependencies = TRUE)
library(htmlwidgets)
}
ui_win <- list()
# first we add what we want to see in the controller to the list
ui_win[["Controller"]] <- fluidPage(
titlePanel("Visnetwork Explorer: Controller")
)
# then we add what we want to see in the floor section
ui_win[["Floor"]] <- fillPage(
# titlePanel("Visnetwork Explorer: Network"),
visNetworkOutput(outputId="network", width = "100%", height = "1080px")
)
ui_win[["Wall"]] <- fluidPage(
titlePanel("visnetmws"),
sidebarLayout(position = "left",
sidebarPanel(
textOutput("node_name"),
imageOutput("node_pic")
),
mainPanel(
textOutput("node_desc")
)
)
)
# setting up the list of calculations I want to do
serv_calc <- list()
# Not sure what goes here for this example
serv_calc[[1]] <- function(input,calc){
}
serv_out <- list()
serv_out[["node_desc"]] <- function (input, calc) {
renderText({
if(!is.null(input$current_node_id)){
if (typeof(input$current_node_id) == "character") {
paste("ID:", input$current_node_id)
}
name <- nodes[input$current_node_id+1, 5]
paste("ID:", input$current_node_id, "\n Name:", name)
} else {
"Node not selected"
}
})
}
# add a image on the wall
serv_out[["node_pic"]] <- function (input, calc) {
renderImage({
if(!is.null(input$current_node_id)){
node_id <<- input$current_node_id
if (typeof(node_id) == "character") {
list(src = "Pictures/Blank.jpg", alt = "No photo available.", width = "400px", height = "400px")
} else {
tmp <<- as.character(nodes[node_id+1, 6])
list(src = tmp, alt = nodes[input$current_node_id+1, 5], width = "400px", height = "400px")
}
}
}, deleteFile = FALSE)
}
# Here we render our network
# note the name is the same as the outputid
serv_out[["network"]] <- function(input, calc){
renderVisNetwork({
# minimal example
nodes <<- read_csv("nodes.csv", col_types = "iccicc")
edges <- read_csv("edges.csv", col_types = "iiic")
myColors <- c("#97c2fc", # 0
"#ffff00", # 1
"#fb7e81", # 2
"#7be141", # 3
"#eb7df4", # 4
"#ad85e4", # 5
"#ffa807", # 6
"#6e6efd", # 7
"#ffc0cb", # 8
"#c2fabc", # 9
"#ff0000", # 10
"#00ff00") # 11
palette() # obtain the current palette
palette(myColors) # Not sure why this is needed, but it is required to set the group node colors correctly
myPalette <- palette(myColors)
groups.closed <- scan("closed.csv", what = "character")
visNetwork(nodes, edges, background="black") %>%
visGroups(groupname = nodes$group[1], color = myColors[1], shape = "circle") %>%
visGroups(groupname = nodes$group[2], color = myColors[2], shape = "circle") %>%
visGroups(groupname = nodes$group[3], color = myColors[3], shape = "circle") %>%
visGroups(groupname = nodes$group[4], color = myColors[4], shape = "circle") %>%
visGroups(groupname = nodes$group[5], color = myColors[5], shape = "circle") %>%
visGroups(groupname = nodes$group[6], color = myColors[6], shape = "circle") %>%
visGroups(groupname = nodes$group[7], color = myColors[7], shape = "circle") %>%
visGroups(groupname = nodes$group[8], color = myColors[8], shape = "circle") %>%
visGroups(groupname = nodes$group[9], color = myColors[9], shape = "circle") %>%
visGroups(groupname = nodes$group[10], color = myColors[10], shape = "circle") %>%
visGroups(groupname = nodes$group[11], color = myColors[11], shape = "circle") %>%
visClusteringByGroup(groups = groups.closed, label = "Group: ",
shape = "circle", color = myPalette, force = TRUE) %>%
#This is the event function: store the nodes id in input$current_node_id
visEvents(selectNode = "function(nodes) {
Shiny.onInputChange('current_node_id', nodes.nodes);
;}")
})
}
# NEW: Run with dependencies
mwsApp(ui_win, serv_calc, serv_out)