-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
101 lines (84 loc) · 3.35 KB
/
app.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
library(tidyverse)
library(plotly)
library(shiny)
source("gpa_exploration_functions.R")
# read data
dat <- read.csv("uiuc-gpa-dataset.csv")
# make the term and yearterm into factors
dat$Term <- factor(dat$Term, c("Spring", "Summer", "Fall", "Winter"))
dat$YearTerm <- factor(dat$YearTerm, paste(rep(2010:2020, each = 4), c("sp", "su", "fa", "wi"), sep = "-"))
dat <- dat %>%
mutate(
Size = A. + A + A..1 + B. + B + B..1 + C. + C + C..1 + D. + D + D..1 + `F`,
Primary.Instructor = ifelse(Primary.Instructor == "", "-", Primary.Instructor)
)
# calculate Average GPA & Class Size for each class
gpa <- c(4,4,3.67,3.33,3.00,2.67,2.33,2.00,1.67,1.33,1.00,0.67,0.00)
lettergrades <- colnames(dat)[str_detect(colnames(dat), "^[ABCDEF]\\.?\\.?[[:digit:]]?$")]
dat$Mean_GPA <- apply(dat[,lettergrades], MARGIN = 1, function(x) sum(x * gpa)) / dat$Size
dat$SD_GPA <- sqrt(apply(dat[,c(lettergrades, "Mean_GPA")], MARGIN = 1, function(x) sum((gpa - x[length(x)])^2 * x[1:(length(x) - 1)])) / dat$Size )
dat$perc_A <- 100 * (dat$A. + dat$A) / dat$Size
all_subjs <- sort(unique(dat$Subject))
ui <- fluidPage(
titlePanel("UIUC GPA Exploration", windowTitle = "UIUC GPA Shiny APP"),
sidebarLayout(
sidebarPanel(
selectInput(
inputId = "Subj", label = "Subject:", choices = all_subjs,
multiple = FALSE, selectize = TRUE
),
selectInput(
inputId = "CourseN", label = "Course Number:", choices = NULL,
multiple = FALSE, selectize = TRUE
),
selectInput(
inputId = "PI", label = "Primary Instructor", choices = NULL,
multiple = TRUE, selectize = TRUE
),
p("Only top 8 instructors with the highest class size are included"),
br(),
actionButton(
inputId = "action", label = "Generate"
),
width = 3
),
mainPanel(
plotlyOutput("gpaplotly", height = "130%"),
plotlyOutput("percAplotly", height = "130%"),
dataTableOutput("all_inst_summary"),
width = 9
)
)
)
server <- function(input, output, session) {
# update course number list based on
observeEvent(input$Subj, {
updateSelectizeInput(
session, "CourseN", label = "Choose Course Number:",
choices = sort(unique(filter(dat, Subject == input$Subj)[["Number"]])))
})
# update PIs
observe({
updateSelectizeInput(
session, "PI", label = "Primary Instructor (up to 8)",
choices = c("Leave Blank for Top 8" = "", sort(unique(filter(dat, Subject == input$Subj & Number == input$CourseN)[["Primary.Instructor"]])))
)
})
gpadat_all_inst <- eventReactive(input$action, {
retrieve_data(dat, input$Subj, input$CourseN)
})
gpadat <- reactive({
get_plotly_gpadat(gpadat_all_inst(), input$PI)
})
gpaplotly <- eventReactive(input$action, {
plotly_average_gpa(gpadat(), input$Subj, input$CourseN)
})
percAplotly <- eventReactive(input$action, {
plotly_percentage_A(gpadat(), input$Subj, input$CourseN)
})
output$gpaplotly <- renderPlotly(gpaplotly())
output$percAplotly <- renderPlotly(percAplotly())
output$all_inst_summary <- renderDataTable(summarise_by_inst(gpadat_all_inst()),
options = list(lengthMenu = c(5, 10, 50), pageLength = 5))
}
shinyApp(ui, server)