forked from rforoperations2019/gradechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
113 lines (109 loc) · 3.74 KB
/
app.R
File metadata and controls
113 lines (109 loc) · 3.74 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
library(shiny)
library(readxl)
library(shinyjs)
library(dplyr)
library(shinythemes)
library(shinydashboard)
file <- "./grades/R Shiny 2021 Grades.xlsx"
passwords <- read_excel(file, sheet = 5)
# Define UI for application that draws a histogram
ui <- dashboardPage(skin = "green",
dashboardHeader(
title = "R Shiny for Operations Management Grade App"
),
dashboardSidebar(
useShinyjs(),
# Login Div
div(id = "auth",
textInput("andrewID",
"Andrew ID:",
placeholder = "Enter you Andrew ID"),
passwordInput("password",
"Password:"),
disabled(actionButton("logIn", "Log In"))
),
selectInput("assignment",
"View Grade for:",
choices = c("Course Grades", "Homework 1", "Homework 2", "Final Project"),
selected = "Course Grades")
),
dashboardBody(
fluidRow(
valueBoxOutput("gradeAverage")
),
# Table with Grades and Comments for the student
fluidRow(
box(width = 12,
DT::dataTableOutput("gradeTable"),
br(),
htmlOutput("gradeComments")
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# Set login to false and save passwords as reactive value
values <- reactiveValues(login = FALSE, passwords = passwords)
# Authenticate Users
observeEvent(input$logIn, {
auth <- read_excel(file, sheet = 5) %>%
filter(`Andrew ID` == input$andrewID)
values$login <- auth$Password == input$password
if (values$login) {
showNotification("You have successfully logged in!")
hide("auth")
} else {
showNotification("Could not match username or password!", type = "error")
}
})
# Check if password fits
observe({
if (input$andrewID %in% values$passwords$`Andrew ID` & nchar(input$password) > 5 & grepl('[^[:alnum:]]', input$password, perl = TRUE)) {
enable("logIn")
} else {
disable("logIn")
}
})
grades <- reactive({
grades <- read_excel(file, sheet = input$assignment) %>%
filter(!is.na(`Last Name`)) %>%
mutate(`Final Grade` = as.numeric(`Final Grade`))
})
# Load Grade Sheet
grade <- reactive({
if (values$login) {
grades() %>%
filter(`Andrew ID` == input$andrewID)
}
})
# Grade Average
output$gradeAverage <- renderValueBox({
value <- mean(grades()$`Final Grade`, na.rm = TRUE)
subtitle <- paste("Avg for ", input$assignment)
valueBox(value = round(value ,2), subtitle = subtitle, icon = icon("check-square"))
})
# Display grade
output$gradeTable <- DT::renderDataTable({
if (is.null(grade())) {
data.frame()
} else if (input$assignment == "Course Grades") {
grade()
} else {
select(grade(), -c(Comments))
}
}, extensions = 'Buttons',
rownames = FALSE,
options = list(dom = 'Bt',
buttons = c('copy', 'csv', 'pdf')
)
)
# Pull comments column and format for HTML output
output$gradeComments <- renderText({
if (input$assignment != "Course Grades") {
paste("<b>Comments:</b><br>", grade()$Comments)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)