-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
99 lines (88 loc) · 3.05 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
library(bslib)
library(shiny)
library(tidyverse)
uwgpa = read_csv(file = "data/uwgpa.csv")
order_grade = c("A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F", "W")
ui = navbarPage(
theme = bs_theme(bootswatch = "cerulean", base_font = font_google("Righteous")),
title = "University of Washington Seattle GPA",
tabPanel(
title = "Input / Visualization",
titlePanel(title = "University of Washington Seattle GPA Data: 2010 - 2015"),
sidebarLayout(
sidebarPanel(
selectInput(
inputId = "year",
label = "Year:",
choices = sort(unique(uwgpa$Year)),
selected = 2010),
selectInput(
inputId = "class",
label = "Class:",
choices = sort(unique(uwgpa$Class))),
selectInput(
inputId = "instructor",
label = "Instructor:",
choices = sort(unique(uwgpa$Instructor))),
checkboxInput(inputId = "course",
label = "Filter Table to Course",
value = FALSE)
),
mainPanel(plotOutput("Plot")))
),
tabPanel(title = "Table", dataTableOutput("table")),
tabPanel(title = "About", includeMarkdown("about.Rmd"))
)
server = function(input, output) {
uwgpa_year = reactive({
uwgpa |>
filter(Year == input$year)
})
observeEvent(
eventExpr = input$year,
handlerExpr = {
updateSelectInput(inputId = "class",
choices = sort(unique(uwgpa_year()$Class)),
selected = sort(unique(uwgpa_year()$Class)))
updateSelectInput(inputId = "instructor",
choices = sort(unique(uwgpa_year_class()$Instructor)),
selected = sort(unique(uwgpa_year_class()$Instructor))[1])
}
)
uwgpa_year_class = reactive({
uwgpa_year() |>
filter(Class == input$class)
})
observeEvent(
eventExpr = input$class,
handlerExpr = {
updateSelectInput(inputId = "instructor",
choices = sort(unique(uwgpa_year_class()$Instructor)),
selected = sort(unique(uwgpa_year_class()$Instructor))[1])
}
)
output$Plot = renderPlot({
uwgpa |>
filter(Year == input$year) |>
filter(Class == input$class) |>
filter(Instructor == input$instructor) |>
pivot_longer(A:W, names_to = "Letter", values_to = "Count") |>
group_by(Letter) |>
summarise(Count = sum(Count)) |>
mutate(Letter = factor(Letter, levels = order_grade)) |>
ggplot() +
aes(x = Letter, y = Count, fill = Letter) |>
geom_bar(stat = "identity") +
theme_bw()
})
output$table = renderDataTable({
tab = uwgpa_year() ##|>
##gpa_calc() ## (Somehow doesn't work when running the app but there's an Average GPA column already though)
if (input$course) {
tab = tab |>
filter(Class == input$class)
}
tab
})
}
shinyApp(ui = ui, server = server)