-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecificCR.R
152 lines (135 loc) · 5.17 KB
/
specificCR.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
selectBuilder <- function(input, output, session) {
crType <- reactive({
# If no file is selected, don't do anything
validate(need(input$crType, message = FALSE))
input$crType
})
getSelects <- reactive({
ns <- session$ns
if (crType() == 'CC') {
renderedPanel <- selectInput(ns("Propc"), dispName('Propc'),
choices = uniquePropc)
} else if (crType() == 'CCC') {
renderedPanel <- fluidRow(
column(6, selectInput(ns("Propc"),dispName('Propc'),
choices = uniquePropc)),
column(6, selectInput(ns("Fcapprop"),dispName('Fcapprop'),
choices = uniqueFcapprop))
)
} else {
renderedPanel <-
selectInput(ns("FracBmsyThreshLo"), dispName('FracBmsyThreshLo'),
choices = uniqueFracBmsyThreshLo)
}
return(renderedPanel)
})
output$crParams <- renderUI({
ns <- session$ns
getSelects()
})
output$low <- renderUI({
ns <- session$ns
if (input$crType == 'BB' | input$crType == 'BB3yr' | input$crType == 'BB5yr' | input$crType == 'BB3yrPerc' )
return (
selectInput(ns("FracBmsyThreshHi"), dispName('FracBmsyThreshHi'),
choices = uniqueFracBmsyThreshHi[
uniqueFracBmsyThreshHi$FracBmsyThreshLo == input$FracBmsyThreshLo, 'FracBmsyThreshHi'])
)
})
output$hi <- renderUI({
ns <- session$ns
if (input$crType == 'BB' | input$crType == 'BB3yr' | input$crType == 'BB5yr' | input$crType == 'BB3yrPerc' )
return (
selectInput(ns("FracFtarg"), dispName('FracFtarg'),
choices = uniqueFracFtarg[uniqueFracFtarg$FracBmsyThreshHi == input$FracBmsyThreshHi &
uniqueFracFtarg$FracBmsyThreshLo == input$FracBmsyThreshLo
,'FracFtarg'])
)
})
}
showSpecificCRResult <- function(input, output, session) {
ns <- session$ns
x <- reactive({
validate(need(input$x, message = FALSE))
input$x
})
y <- reactive({
validate(need(input$y, message = FALSE))
input$y
})
xy <- reactive({
crRes = allres[allres$CR == input$crType,]
if (input$crType == 'CC') {
if (!is.null(input$Propc))
selectedRes <- crRes[crRes$Propc == input$Propc,]
} else if (input$crType == 'CCC') {
if (!is.null(input$Propc) & !is.null(input$Fcapprop))
selectedRes <- crRes[crRes$Propc == input$Propc &
crRes$Fcapprop == input$Fcapprop,]
} else {
if (!is.null(input$FracBmsyThreshHi) & !is.null(input$FracBmsyThreshLo) & !is.null(input$FracFtarg)) {
selectedRes <- crRes[crRes$FracBmsyThreshHi == input$FracBmsyThreshHi &
crRes$FracBmsyThreshLo == input$FracBmsyThreshLo &
crRes$FracFtarg == input$FracFtarg,]
}
}
if (exists("selectedRes")) {
return (selectedRes)
}
})
output$distPlot <- renderPlot({
xyVal <- xy()
x25id = get25(x())
x75id = get75(x())
y25id = get25(y())
y75id = get75(y())
if (!is.null(xyVal) && !is.na(xyVal) && nrow(xyVal) > 0) {
pll <- ggplot(xyVal, aes_string(x=input$x, y=input$y, color='bias', shape='steep'))
if (!is.null(x25id) && !is.na(x25id) && x25id != "" ) {
x1 <- xyVal[x()]-xyVal[x25id]
y <- xyVal[y()]
x2 <- xyVal[x()]+xyVal[x75id]
dd <- data.frame(x1, y, x2)
pll <- pll +
geom_segment(aes(x=xyVal[x()]-xyVal[x25id], y=xyVal[y()], xend=xyVal[x()]+xyVal[x75id], yend=xyVal[y()]), alpha=1)
}
if (!is.null(y25id) && !is.na(y25id) && y25id != "" ) {
pll <- pll +
geom_segment(aes(x=xyVal[x()], y=xyVal[y()]-xyVal[y25id], xend=xyVal[x()], yend=xyVal[y()]+xyVal[y75id]), alpha=1)
}
pll +
geom_point(size=3, alpha=1) +
theme_classic() +
xlab(dispName(x())) +
ylab(dispName(y()))
#+
# theme(plot.title = element_text(hjust = 0.5))
}
})
get25 <- function(metric) {
if (!is.null(metric) && !is.na(metric)) {
if (length(grep(paste("Q25",substring(metric, 4), sep=""), v25)) > 0)
return (paste("Q25",substring(metric, 4), sep=""))
else if (length(grep(paste(metric, "_25", sep=""), v25)) > 0)
return (paste(metric, "_25", sep=""))
}
return(NULL)
}
get75 <- function(metric) {
if (!is.null(metric) && !is.na(metric)) {
if (length(grep(paste("Q75",substring(metric, 4), sep=""), v75)) > 0)
return (paste("Q75",substring(metric, 4), sep=""))
else if (length(grep(paste(metric, "_75", sep=""), v75)) > 0)
return (paste(metric, "_75", sep=""))
}
return(NULL)
}
output$view <- renderTable({
res <- xy()
if (!is.null(res) && !is.na(res) && nrow(res) > 0) {
res <- res[c("Bias", "Steep", x(), y())]
colnames(res) <- c("Bias", "Steep", toString(dispName(x())), toString(dispName(y())))
return (res)
}
})
}