forked from chendaniely/construct_wiki_mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
96 lines (80 loc) · 3.21 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
library(shiny)
# helpful
# https://gist.github.com/tbadams45/38f1f56e0f2d7ced3507ef11b0a2fdce
# https://www.rstudio.com/resources/webinars/understanding-shiny-modules/
# https://gist.github.com/bborgesr/e1ce7305f914f9ca762c69509dda632e
# https://stackoverflow.com/questions/21636023/r-shiny-simple-reactive-issue
# http://shiny.leg.ufpr.br/daniel/025-loop-ui/
# https://shiny.rstudio.com/gallery/creating-a-ui-from-a-loop.html
# Define server logic required to draw a histogram
shinyServer(function(input, output, session) {
constructs <- reactive({
if (input$radio_data == ORIGINAL_DATA) {
return(ORIGINAL_DATA_DF)
} else if (input$radio_data == ADJUSTED_DATA) {
return(ADJUSTED_DATA_DF)
}
})
# pokemon <- read.csv('data/pokemon.csv', sep = '\t', stringsAsFactors = FALSE)
construct_values <- reactive({
cv <- constructs()$construct
names(cv) <- str_to_title(cv)
return(cv)
})
network_dfs <- reactive({
.GlobalEnv$clean_network_df(constructs())
})
# G <- igraph::graph_from_data_frame(network_dfs$edges)
# neighbors(G, 'character')
# this is just to test if the thing actually works...
# visNetwork(network_dfs$nodes, network_dfs$edges, width = '100%', height = "1000px") %>%
# visEdges(arrows = "to") %>%
# visOptions(manipulation = TRUE,
# collapse = TRUE) %>%
# visLayout(randomSeed = 42)
output$vis_network <- renderVisNetwork({
visNetwork(network_dfs()$nodes, network_dfs()$edges, width = "100%", height = "75%") %>%
visEdges(arrows = "from") %>%
visOptions(manipulation = TRUE,
collapse = TRUE) %>%
visLayout(randomSeed = 42)
})
output$construction_selection <- renderUI({
selectizeInput('construct_name', 'Select Construct(s)', c(Choose = '', sort(construct_values())), multiple = TRUE)
})
construct_row_dat <- reactive({
construct_row_dat <- constructs()[constructs()$construct %in% input$construct_name,
c('construct', 'definition', 'field', 'military',
'population', 'measurement', 'instrument', 'notes')]
print(construct_row_dat)
print('returning construct_row_dat')
print('type')
print(class(construct_row_dat))
return(construct_row_dat)
})
num_defs <- reactive({
ndefs <- nrow(construct_row_dat)
print(ndefs)
return(ndefs)
})
output$construct_definition_dt <- DT::renderDataTable({
construct_row_dat()
},
extensions = c('Responsive', 'Buttons'),
options = list(pageLength = -1,
#lengthMenu = c(5, 10, 15, 20, 50, 100, nrow(.GlobalEnv$constructs())),
#colReorder = TRUE,
#fixedHeader = TRUE,
dom = 'Bt'
)
)
output$construct_dt <- DT::renderDataTable({
constructs()
},
extensions = 'Responsive',
options = list(pageLength = -1#,
#lengthMenu = c(5, 10, 15, 20, 50, 100, num_defs()),
#colReorder = TRUE,
#fixedHeader = TRUE
))
})