-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.R
466 lines (420 loc) · 22.2 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(plotly)
library(shinydashboardPlus)
library(colorspace)
library(tidyverse)
## Loading the data
load("./rData/allFSAData.rData")
load("./rData/CATCData.rData")
load("./rData/modelresult.Rdata")
# load("./rData/FAFSA_SchoolApplicationData.rData")
options(rsconnect.error.trace = TRUE)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
values <- reactiveValues(colors5 = lighten(c("#e27D60", "#85CDCB", "#e8A87C", "#c38d9e", "#41B3A3"), 0.5))
##### UI Section #####
output$selectedUni_Ind <- renderUI({
uniqueList <- allFSAData_Key$UniversityName
pickerInput(
inputId = "selectedUni_Ind",
label = "Select the University You want to Investigate: ",
choices = uniqueList,
selected = "NORTH CAROLINA STATE UNIVERSITY",
options = list(
`live-search` = TRUE,
liveSearchPlaceholder = "Search a Parameter:",
size = 10
)
# color = "success",
# icon = icon("hire-a-helper")
)
})
output$selectedUni_Ind_DLCat <- renderUI({
uniqueList <- unique(DL_ColumnKey$DLCategory)
pickerInput(
inputId = "selectedUni_Ind_DLCat",
label = "Direct Loan Cateogry to Ingestigate: ",
choices = uniqueList,
selected = uniqueList[1]
)
})
output$selectedUni_Ind_Cat <- renderUI({
uniqueList <- unique(DL_ColumnKey$category)
pickerInput(
inputId = "selectedUni_Ind_Cat",
label = "Select A Direct Loan Variable to Investigate: ",
choices = uniqueList,
selected = uniqueList[1]
)
})
##### Individual Info Box #####
output$scorecard <- renderInfoBox({
req(input$selectedUni_Ind)
curUni <- input$selectedUni_Ind
infoBox("Link to ", "U.S. Department of Education - College Scorecard",
icon = icon("school"), fill = TRUE, color = "maroon", width = 6, # north%20Carolina%20State
href = paste0("https://collegescorecard.ed.gov/search/?search=",
gsub(" ", "%20", curUni),
"&page=0&sort=completion_rate:desc&toggle=institutions"))
})
output$googleSearch <- renderInfoBox({
req(input$selectedUni_Ind)
curUni <- input$selectedUni_Ind
infoBox("Link to ", HTML("Google Search Link for the Selected University "),
icon = icon("google"), fill = TRUE, color = "teal", width = 6, # north%20Carolina%20State
href = paste0("https://www.google.com/search?q=",
gsub(" ", "+", curUni))
)
})
output$topUni <- renderInfoBox({
req(input$selectedUni_Ind)
curUni <- input$selectedUni_Ind
infoBox("Link to ", "University Search for the Selected University",
icon = icon("globe-americas"), fill = TRUE, color = "green", width = 6, # north%20Carolina%20State
href = paste0("https://www.topuniversities.com/search/all#q=",
gsub(" ", "%20", curUni)))
})
##### Individual Bar Line Plot #####
output$individualQuarterlyPlot <- renderPlotly({
req(input$selectedUni_Ind)
curUni <- input$selectedUni_Ind
curDLCat <- input$selectedUni_Ind_DLCat
curCat <- input$selectedUni_Ind_Cat
colors5 <- values[["colors5"]]
curDLCat_Ori <- as.character(subset(DL_ColumnKey, DLCategory == curDLCat & category == curCat)$original)
print(curDLCat_Ori)
subData <- allFSAData %>%
filter(UniversityName == curUni) %>%
select(UniversityName, one_of(curDLCat_Ori), State, Zip.Code, School.Type, Year, OriQuarter) %>%
pivot_wider(names_from = Year, values_from = one_of(curDLCat_Ori))
curState <- subData$State[1]
stateAverage <- stateAvg %>%
select(State, OriQuarter, one_of(curDLCat_Ori)) %>%
filter(State == curState) %>%
rename(curCol = one_of(curDLCat_Ori))
nationalAverage <- nationalAvg %>%
select(OriQuarter, one_of(curDLCat_Ori)) %>%
rename(curCol = one_of(curDLCat_Ori))
subData %>%
plot_ly() %>%
add_trace(
y = ~`2015`,
type = ~"bar",
name = "2015",
x = ~OriQuarter,
legendgroup = "group1",
marker = list(color = colors5[1],
line = list(color = darken(colors5[1], 0.3),
width = 2))) %>%
add_trace(y = ~`2016`, name = "2016",
x = ~OriQuarter,
legendgroup = "group1",
marker = list(color = colors5[2],
line = list(color = darken(colors5[2], 0.3),
width = 2)))%>%
add_trace(y = ~`2017`, name = "2017",
x = ~OriQuarter,
legendgroup = "group1",
marker = list(color = colors5[3],
line = list(color = darken(colors5[3], 0.3),
width = 2)))%>%
add_trace(y = ~`2018`, name = "2018",
x = ~OriQuarter,
legendgroup = "group1",
marker = list(color = colors5[4],
line = list(color = darken(colors5[4], 0.3),
width = 2)))%>%
add_trace(y = ~`2019`, name = "2019",
x = ~OriQuarter,
legendgroup = "group1",
marker = list(color = colors5[5],
line = list(color = darken(colors5[5], 0.3),
width = 2))) %>%
add_trace(data = nationalAverage,
x = ~OriQuarter,
y = ~curCol,
legendgroup = "group2",
name = "National Average",
type = "scatter",
mode = "lines+markers",
marker = list(size = 15,
line = list(color = "#000000",
size = 5))) %>%
add_trace(data = stateAverage,
x = ~OriQuarter,
y = ~curCol,
legendgroup = "group2",
name = "State Average",
type = "scatter",
mode = "lines+markers",
marker = list(size = 15,
line = list(color = "#000000",
size = 5))) %>%
layout(
# title = paste0("Direct Loans: ", curDLCat, " - ", curCat),
xaxis = list(title = "<b>Quarter</b>"),
yaxis = list(title = paste0(" <b>", curDLCat, " <br> ", curCat, "</b>")))
})
##### Individual Tuition Chart #####
output$tuitionNetPricePlot <- renderPlotly({
req(input$tuitionInfoSelector)
colors5 <- values[["colors5"]]
curData <- tuitionFull
curOPE <- allFSAData_Key$OPE.ID[match(input$selectedUni_Ind, allFSAData_Key$UniversityName)]
curData <- tuitionFull %>%
filter(OPEID == curOPE)
if(nrow(curData) > 1){
if(input$tuitionInfoSelector == "TuitionAndFees"){
curData <- tuitionFull
curOPE <- allFSAData_Key$OPE.ID[match(input$selectedUni_Ind, allFSAData_Key$UniversityName)]
curData <- tuitionFull %>%
filter(OPEID == curOPE)
print(curData)
plot_ly(curData,
x = ~Year,
y = ~TuitionAndFees ,
type = "scatter",
mode = "lines+markers",
marker = list(color = colors5[5],
line = list(color = darken(colors5[5], 0.3),
width = 15))
) %>%
layout(
xaxis = list(title = "<b>Academic Year</b>"),
yaxis = list(title = "<b>Tuition and Fees ($)</b>")
)
# curData <- filter()
} else {
curOPE <- allFSAData_Key$OPE.ID[match(input$selectedUni_Ind, allFSAData_Key$UniversityName)]
curData <- netPriceFull %>%
filter(OPEID == curOPE)
print(curData)
if(input$tuitionInfoSelector == "NetPrice"){
plot_ly(curData,
x = ~Year,
y = ~NetPrice,
type = "scatter",
mode = "lines+markers",
marker = list(color = colors5[5],
line = list(color = darken(colors5[5], 0.3),
width = 15))
) %>%
layout(
xaxis = list(title = "<b>Academic Year</b>"),
yaxis = list(title = "<b>Net Price ($)</b>")
)
} else {
plot_ly(curData,
x = ~Year,
y = ~PercentReceivingGrantAid,
type = "scatter",
mode = "lines+markers",
marker = list(color = colors5[5],
line = list(color = darken(colors5[5], 0.3),
width = 15))
) %>%
layout(
xaxis = list(title = "<b>Academic Year</b>"),
yaxis = list(title = "<b>Percent Receiving Grant Aid (%)</b>")
)
}
}
}
})
##### Linear Model #####
output$selectedUni_Model_DLCat <- renderUI({
uniqueList <- unique(DL_ColumnKey$DLCategory)
pickerInput(
inputId = "selectedUni_Model_DLCat",
label = "Direct Loan Cateogry to Ingestigate: ",
choices = uniqueList,
selected = uniqueList[1]
)
})
output$selectedUni_Model_Cat <- renderUI({
uniqueList <- unique(DL_ColumnKey$category)
pickerInput(
inputId = "selectedUni_Model_Cat",
label = "Select A Direct Loan Variable to Investigate: ",
choices = uniqueList,
selected = uniqueList[1]
)
})
output$LinaerModelFitPlot <- renderPlotly({
req(input$selectedUni_Ind)
curUni <- input$selectedUni_Ind
curDLCat <- input$selectedUni_Model_DLCat
curCat <- input$selectedUni_Model_Cat
curOPE <- allFSAData_Key$OPE.ID[match(input$selectedUni_Ind, allFSAData_Key$UniversityName)]
curDLCat_Ori <- as.character(subset(DL_ColumnKey, DLCategory == curDLCat & category == curCat)$original)
modelData <- modeldata1 %>%
select("OPE.ID", "Year", one_of(curDLCat_Ori)) %>%
filter(OPE.ID == curOPE) %>%
rename(curCol = one_of(curDLCat_Ori))
modelData$curCol <- as.double(as.character(modelData$curCol))
modelData$Year <- factor(modelData$Year)
print(modelData)
### Linear Trend calculation
modelOutput <- allresult_r[[curOPE]]
modelOutput <- modelOutput %>% as_tibble() %>%
select(one_of(curDLCat_Ori))
curBeta0 <- modelOutput[1,1]
curBeta1 <- modelOutput[2,1]
curR2 <- modelOutput[3,1]
curP <- modelOutput[4,1]
curSE <- modelOutput[5,1]
curModelTable <- data.frame(
"Estimate of Rate of Change" = round(as.numeric(curBeta1), 3),
"Standard Error" = round(as.numeric(curSE), 3),
"P-Value" = round(as.numeric(curP), 3),
"R-Squared" = round(as.numeric(curR2), 3)
)
colnames(curModelTable) <- c("Estimate of Rate of Change", "Standard Error",
"P Value", "R-Squared")
print(curModelTable)
print(modelOutput)
output$modelTable <- DT::renderDataTable({
# data.select %>% dplyr::select(-UniqueID)
curModelTable
},
rownames= FALSE,
options = list(
searching = FALSE, info = FALSE,
lengthChange = FALSE, bPaginate = FALSE
)
)
yearlyTrend <- data.frame("Year" = as.character(2015:2019),
"curCol" = c(
as.numeric(curBeta0 + curBeta1*2015),
as.numeric(curBeta0 + curBeta1*2016),
as.numeric(curBeta0 + curBeta1*2017),
as.numeric(curBeta0 + curBeta1*2018),
as.numeric(curBeta0 + curBeta1*2019)
)
)
# print(yearlyTrend)
modelData %>%
plot_ly() %>%
add_trace(
x = ~Year,
y = ~curCol,
mode = "markers",
type = "scatter",
marker = list(size = 10,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2)),
name = "Yearly Sum"
) %>%
add_trace(
data = yearlyTrend,
x = ~Year,
y = ~curCol, type = 'scatter', mode = 'lines',
line = list(color = 'rgb(22, 96, 167)', width = 4),
name = "Linear Model Fit"
) %>%
layout(
xaxis = list(title = "<b>Year</b>"),
yaxis = list(title = paste0(" <b>", curDLCat, " <br> ", curCat, "</b>"))
)
})
##### Modal #####
observeEvent(input$individualQuarterlyHelp, {
# Show a modal when the button is pressed
showModal(modalDialog(
title = "Data Description",
tags$img(src = "FSA.png", align = "center", width = "400"),
HTML("<br><br>
<b>Data Source</b>:<br>
Common Origination and Disbursement (COD) System<br>
<a href='https://studentaid.gov/data-center/student/title-iv'>https://studentaid.gov/data-center/student/title-iv</a><br>
<b>Recipients</b>:<br>
The number of loan recipients for the loan type during the award year for the time period reported on the spreadsheet. For Subsidized, Unsubsidized, and Graduate PLUS loans, this is a count of student borrowers. For Parent PLUS loans, this is a count of the students on whose behalf the loan was taken. Since students can have multiple loan types in the same award year, you cannot sum the recipient counts from the four categories to obtain an accurate count of total recipients for the loan program during that award year. <br>
<b># of Loans Originated</b>:<br>
The number of loans initiated for the loan type during the award year for the time period reported on the spreadsheet. <br>
<b>$ of Loans Originated</b>:<br>
The dollar amount of the loans initiated for the loan type during the award year for the time period reported on the spreadsheet. This is the expected total loan amount if the loan is fully disbursed. <br>
<b># of Loans Disbursed</b>:<br>
The number of disbursements made for the loan type during the award year and quarter reported on the spreadsheet. <br>
<b>$ of Loans Disbursed</b>:<br>
The dollar amount of disbursements made for the loan type during the award year for the time period reported on the spreadsheet.
"),
# tags$img(src = "workingOnIt.gif"),
easyClose = TRUE
))
})
observeEvent(input$individualTuitionHelp, {
# Show a modal when the button is pressed
showModal(modalDialog(
title = "Data Description",
tags$img(src = "CAT.png", align = "center", width = "400"),
HTML("<br><br><b>Data Source</b>:<br>
College Affordability and Transparency Data Files, 2014 - 2019 <br>
<a href='https://collegecost.ed.gov/affordability'>https://collegecost.ed.gov/affordability</a>
<br>
<b>Tuition and Fees</b>: <br>
Tuition and required fees for full-time, first-time degree/certificate-seeking students at Title IV institutions are sorted by sector of institution and degree sought after for that academic year.
For institutions that charge different tuition for in-district, in-state, or out-of-state students, the minimum tuition (in-district) was used. <br>
<b>Net price</b>:<br>
This figure plots average net price of attendance for full-time, first-time degree/certificate-seeking students at Title IV institutions sorted by sector of institution and degree sought after for that academic
year
The Higher Education Act, as amended, defines institutional net price as \"the average yearly price actually charged to first-time, full-time undergraduate students receiving student aid at an institution of
higher education after deducting such aid.\"
In IPEDS, average institutional net price is generated by subtracting the average amount of federal, state/local government, or institutional grant and scholarship aid from the total cost of attendance.
Total cost of attendance is the sum of published tuition and required fees (lower of in-district or in-state for public institutions), books and supplies, and the weighted average for room and board and other
expenses. <br>
<b>Percent receiving Grant Aid:</b>: <br>
This figure plots the percentage of students receiving grant for full-time, first-time degree/certificate-seeking students at Title IV institutions sorted by sector of institution and degree sought after for that academic year
"),
# tags$img(src = "workingOnIt.gif"),
easyClose = TRUE
))
})
observeEvent(input$individualTuitionAssumption, {
# Show a modal when the button is pressed
showModal(modalDialog(
title = "Assumption Description",
tags$img(src = "FSA.png", align = "center", width = "400"),
HTML("<br><br><b>Data Source</b>:<br>
Common Origination and Disbursement (COD) System <br>
<a href='https://studentaid.gov/data-center/student/title-iv'>https://studentaid.gov/data-center/student/title-iv</a> <br>
<b>Assumptions</b>:<br>
<b>1. </b>Loans are included in the columns RECIPIENTS, # OF LOANS ORIGINATED, $ OF LOANS ORIGINATED, # OF DISBURSEMENTS, and $ OF DISBURSEMENTS if the period begin date of the loan falls within the award year reported on the spreadsheet and the first disbursement of that loan falls within that quarter. Disbursements occurring prior to the award year are counted in quarter 1 and disbursements occurring after the end of the award year are counted in quarter 4. For the Year-To-Date data, all numbers are cumulative. <br>
<b>2. </b>Disbursements are included in the columns # OF DISBURSEMENTS and $ OF DISBURSEMENTS if the loan was included in the loan origination counts and the dates of the disbursements were less than or equal to the last day of the quarter reported on this spreadsheet. For fourth quarter reports it is the cumulative number of disbursements as of the date the report is created in order to include any late disbursements. Disbursements for the second, third, and fourth quarters are cumulative from the beginning of the award year. <br>
<b>3. </b>Consolidation loans are not included in either query. <br>
<b>4. </b>A school appears on the report only if at least one loan originated at that school qualifies f <br>or inclusion on the report. <br>
<b>5. </b>Loans with a current loan status of cancelled are excluded from both queries. <br>
<b>6. </b>Disbursements in history with an amount of zero are not counted in the number of disbursements. <br>
"),
# tags$img(src = "workingOnIt.gif"),
easyClose = TRUE
))
})
observeEvent(input$linearModelHelp, {
# Show a modal when the button is pressed
showModal(modalDialog(
title = "Data Description",
tags$img(src = "FSA.png", align = "center", width = "400"),
HTML("<br><br><b>Data Source</b>:<br>
Common Origination and Disbursement (COD) System <br>
<a href='https://studentaid.gov/data-center/student/title-iv'>https://studentaid.gov/data-center/student/title-iv</a> <br>
<b>Linear model :</b><br>
By observing that the trend of the overall pattern from 2015-2016 to 2019-2020 school year is approximately linear,
we use a linear model to capture the change of each loan type overall the year. We reported the OLS estimate of the change rate coefficient,
the standard error of the estimate, p-value of the estimate, and the R-square.
"),
# tags$img(src = "workingOnIt.gif"),
easyClose = TRUE
))
})
})