-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
67 lines (42 loc) · 2.08 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
library(shiny)
shinyServer(function(input, output) {
output$tree <- renderCollapsibleTree({
collapsibleTreeNetwork(df = df_fam[,1:2], collapsed = F)
})
output$tree_filter <- renderCollapsibleTree({
fam_tree <- df_fam[-1,] %>%
mutate_at(vars(parent, child), str_replace_all, " ", "_") %>%
FromDataFrameNetwork()
name <- str_replace_all(input$treeid, " ", "_")
FindNode(fam_tree,name) %>%
ToDataFrameNetwork() %>%
rename(parent = from,
child = to) %>%
mutate_at(vars(parent, child), str_replace_all, "_", " ") %>%
left_join(df_fam) %>%
bind_rows( data.frame(parent = NA, child = name)) %>%
collapsibleTreeNetwork(df = .[,1:2], collapsed = F)
})
output$tree_search <- renderCollapsibleTree({
fam_tree <- df_fam[-1,] %>%
mutate_at(vars(parent, child), str_replace_all, " ", "_") %>%
FromDataFrameNetwork()
name1 <- str_replace_all(input$name1, " ", "_")
name2 <- str_replace_all(input$name2, " ", "_")
path1 <- FindNode(fam_tree, name1)$path
path2 <- FindNode(fam_tree, name2)$path
ancestor <- last(path1[path1 %in% path2])
FindNode(fam_tree, ancestor) %>%
ToDataFrameNetwork() %>%
rename(parent = from,
child = to) %>%
mutate_at(vars(parent, child), str_replace_all, "_", " ") %>%
left_join(df_fam) %>%
bind_rows( data.frame(parent = NA, child = ancestor)) %>%
mutate(col = case_when(child %in% str_replace_all(c(name1, name2), "_"," ") ~ "#cd2626",
child == ancestor ~ "#1874cd",
TRUE ~ "#FFFFFF")) %>%
select(-generation) %>%
collapsibleTreeNetwork(collapsed = F, fill = "col")
})
})