-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
executable file
·200 lines (141 loc) · 4.52 KB
/
server.R
File metadata and controls
executable file
·200 lines (141 loc) · 4.52 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(gplots)
require(reshape2)
library(flowr)
source("funcs2.R")
as.c=as.character
#source("~/Dropbox/public/github_flow/R/plot-funcs.R")
## http://shiny.rstudio.com/gallery/widgets-gallery.html
## http://stackoverflow.com/questions/22160372/r-shiny-how-to-build-dynamic-ui-text-input
## for each job we have:
## jobname
## cmd
## previous_job
## submission_type
## dependency_type
shinyServer(func = function(input, output, session){
##print(url_fields_to_sync)
firstTime <- TRUE
source("funcs2.R")
output$hash <- renderText({
#url_fields_to_sync <- as.c(names(input))
#if(length(url_fields_to_sync) == 0)
url_fields_to_sync = c("num_jobs", "refresh")
newHash = paste(collapse=",",
Map(function(field) {
paste(sep="=",
field,
input[[field]])
},
url_fields_to_sync))
# the VERY FIRST time we pass the input hash up.
return(
if (!firstTime) {
newHash
} else {
if (is.null(input$hash)) {
NULL
} else {
firstTime<<-F;
isolate(input$hash)
}
}
)
})
output$jobs = renderUI({
## make a new UI, when ever either of these change their value
input$num_jobs;
input$refresh
#print(get_jobnames(input))
isolate({
get_jobforms(input)
})
})
#outputOptions(output, 'jobs', suspendWhenHidden=FALSE)
#----------- get the dat to be used in the later steps
#debug(get_flow_table)
current_def <- reactive({
if (input$num_jobs < 1)
return("")
# get this only if we have more than 0 jobs
message("class of input is: ")
#print(class(input))
to_flowdef(input)
})
# --------- flow summary table, this is really a flowdef
output$flow_def <- renderTable({
## need atleast one job
#browser()
if (input$num_jobs < 1)
return()
def <- current_def()
return(as.data.frame(def))
}, include.rownames=FALSE)
# ------------------------------------- output flowdef -------------------------------
output$download_flowdef <- downloadHandler(
filename = function() {
paste(input$flow_name, '.def', sep='')
},
content = function(file) {
# get this only if we have more than 2 jobs
def <- current_def()
params::write_sheet(def, file)
})
# -------------------------- flow summary plot ----------------------------------------------------
#debug(.plot_flow_dat)
output$flow_diagram <- renderPlot({
#browser()
# ------- proceed only when we have more than 2 jobs
if (input$num_jobs < 2)
return(textplot(c('Add some jobs using the slider below\n', 'Say more than 3 ...')))
def <- try(current_def())
if(class(def)[1] == "try-error"){
textplot("please refresh ...")
}
else{
plot_flow(def)
}
})
# ------------------------------------- download the plot made earlier -------------------------------
output$downloadPlot <- downloadHandler(
filename = function() { paste(input$flow_name, '.pdf', sep='') },
content = function(file) {
# get this only if we have more than 2 jobs
if (input$num_jobs < 2)
return("")
pdf(file)
def <- current_def()
plot_flow(def)
dev.off()
})
current_flow_code <- reactive({
to_flowcode(input=input)
})
# ------------------------------------- output code -------------------------------
output$code <- renderUI({
#debug(get_dat_flowcode)
flow_code <- current_flow_code()
#print(flow_code)
ret <- pre(class="shiny-code",
# we need to prevent the indentation of <code> ... </code>
HTML(format(tags$code(
class="language-r",
#paste(readLines(file.path.ci(getwd(), rFile), warn=FALSE),collapse="\n")
paste(flow_code, collapse = "\n")
), indent = FALSE)))
return(ret)
})
output$rscript <- downloadHandler(
filename = function () {
paste(input$flow_name, '.R', sep='')
},
content = function(file) {
flow_code <- current_flow_code()
write(flow_code, file)
})
}) ## server