imupset27 commited on
Commit ·
16495d2
1
Parent(s): 95b5580
update
Browse files- .Rhistory +3 -0
- app original.R +201 -0
- app.R +11 -5
.Rhistory
CHANGED
|
@@ -1 +1,4 @@
|
|
| 1 |
shiny::runApp()
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
shiny::runApp()
|
| 2 |
+
library(shiny); runApp('app2.R')
|
| 3 |
+
shiny::runApp()
|
| 4 |
+
runApp()
|
app original.R
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Load required libraries
|
| 2 |
+
library(shiny)
|
| 3 |
+
library(readxl)
|
| 4 |
+
library(tidyverse)
|
| 5 |
+
library(stringr)
|
| 6 |
+
library(openxlsx)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
timeoutSeconds <- 1
|
| 10 |
+
|
| 11 |
+
inactivity <- sprintf("
|
| 12 |
+
function idleTimer() {
|
| 13 |
+
var t;
|
| 14 |
+
var timeout = %s * 1000; // Convert seconds to milliseconds
|
| 15 |
+
|
| 16 |
+
// Events that reset the timer
|
| 17 |
+
var events = ['mousemove', 'mousedown', 'click', 'scroll', 'keypress'];
|
| 18 |
+
|
| 19 |
+
// Function to log out
|
| 20 |
+
function logout() {
|
| 21 |
+
Shiny.setInputValue('timeOut', '%s');
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// Function to reset the timer
|
| 25 |
+
function resetTimer() {
|
| 26 |
+
clearTimeout(t);
|
| 27 |
+
t = setTimeout(logout, timeout);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// Attach resetTimer to each event
|
| 31 |
+
events.forEach(function(event) {
|
| 32 |
+
window.addEventListener(event, resetTimer);
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
// Initialize the timer
|
| 36 |
+
t = setTimeout(logout, timeout);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// Initialize the idle timer
|
| 40 |
+
idleTimer();
|
| 41 |
+
", timeoutSeconds, timeoutSeconds)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
#####
|
| 45 |
+
read_and_preprocess <- function(path, filename) {
|
| 46 |
+
df <- read_excel(path)
|
| 47 |
+
|
| 48 |
+
# Remove columns with entirely NA entries
|
| 49 |
+
df <- df[, colSums(is.na(df)) != nrow(df), drop = FALSE]
|
| 50 |
+
|
| 51 |
+
columns_selected <- c("ID number", "Last name", "Time taken", "State", "Grade/5.00")
|
| 52 |
+
new_column_names <- c("ID_Number", "Last_Name", "Time_Taken", "State", "Grade")
|
| 53 |
+
|
| 54 |
+
# Select and rename columns
|
| 55 |
+
df <- df[, columns_selected, drop = FALSE]
|
| 56 |
+
colnames(df) <- new_column_names
|
| 57 |
+
|
| 58 |
+
# Convert Grade to numeric and Last_Name to title case
|
| 59 |
+
df$Grade <- as.numeric(df$Grade)
|
| 60 |
+
df$Last_Name <- str_to_title(df$Last_Name)
|
| 61 |
+
|
| 62 |
+
# Remove rows with missing values
|
| 63 |
+
df <- df[complete.cases(df), ]
|
| 64 |
+
|
| 65 |
+
return(df)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# Function to calculate additional columns
|
| 69 |
+
calculate_additional_columns <- function(df, attempted, filename) {
|
| 70 |
+
avg_col_name <- paste("Average", filename, sep = "_")
|
| 71 |
+
|
| 72 |
+
df <- df %>%
|
| 73 |
+
group_by(ID_Number) %>%
|
| 74 |
+
mutate(nAttempt = n(),
|
| 75 |
+
!!avg_col_name := ifelse(nAttempt >= attempted,
|
| 76 |
+
round(mean(sort(Grade, decreasing = TRUE)[1:attempted]),0),
|
| 77 |
+
round(sum(Grade) / attempted))) %>%
|
| 78 |
+
distinct(ID_Number, .keep_all = TRUE)
|
| 79 |
+
|
| 80 |
+
return(df)
|
| 81 |
+
}
|
| 82 |
+
#####
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# Define UI
|
| 87 |
+
ui <- fluidPage(
|
| 88 |
+
tags$script(HTML(inactivity)),
|
| 89 |
+
titlePanel(
|
| 90 |
+
h4("UTAS - Online Marks Aggregator"),
|
| 91 |
+
windowTitle = "Marks Aggregator"
|
| 92 |
+
),
|
| 93 |
+
|
| 94 |
+
sidebarLayout(
|
| 95 |
+
sidebarPanel(
|
| 96 |
+
numericInput(
|
| 97 |
+
"attempt",
|
| 98 |
+
"Min Number of Attempts",
|
| 99 |
+
value = 1, min = 1, max = 10, step = 1
|
| 100 |
+
),
|
| 101 |
+
|
| 102 |
+
fileInput(
|
| 103 |
+
"files",
|
| 104 |
+
"Upload Excel file(s)",
|
| 105 |
+
accept = c(".xlsx"),
|
| 106 |
+
multiple = TRUE,
|
| 107 |
+
placeholder = "Please select excel file/s"
|
| 108 |
+
),
|
| 109 |
+
|
| 110 |
+
helpText("Upload only Excel files with .XLSX extension to ensure consistency."),
|
| 111 |
+
br(),
|
| 112 |
+
downloadButton("downloadData", "Download"),
|
| 113 |
+
hr(),
|
| 114 |
+
|
| 115 |
+
div(
|
| 116 |
+
class = "fluent-footer",
|
| 117 |
+
div(
|
| 118 |
+
class = "fluent-footer-legal",
|
| 119 |
+
div(
|
| 120 |
+
class = "fluent-footer-legal-left",
|
| 121 |
+
a("Privacy Policy", href = "#"),
|
| 122 |
+
" | ",
|
| 123 |
+
a("Terms of Use", href = "#")
|
| 124 |
+
),
|
| 125 |
+
div(
|
| 126 |
+
class = "fluent-footer-legal-right",
|
| 127 |
+
"© 2023 College of Computing and Information Sciences"
|
| 128 |
+
)
|
| 129 |
+
)
|
| 130 |
+
),
|
| 131 |
+
|
| 132 |
+
tags$footer(
|
| 133 |
+
style = "text-align: left; padding-top: 10px; font-size: 12px;",
|
| 134 |
+
"Built by ",
|
| 135 |
+
tags$a(href = "https://www.google.com/search?q=dr.+eduardo+lacap+jr&sca_esv=4136c3af1df3852c&sca_upv=1&sxsrf=ADLYWIIeq7fb1cWKSiyieFVwGRe7qJ40NA%3A1716361100562&ei=jJdNZqHvIZbeseMPj4O8sAs&oq=dr.+eduardo+lacap&gs_lp=Egxnd3Mtd2l6LXNlcnAiEWRyLiBlZHVhcmRvIGxhY2FwKgIIATIHECMYsAMYJzIHECMYsAMYJzILEAAYgAQYsAMYogQyCxAAGIAEGLADGKIEMgsQABiwAxiiBBiJBTILEAAYgAQYsAMYogRIuA1QAFgAcAF4AJABAJgBAKABAKoBALgBAcgBAJgCAaACBJgDAIgGAZAGBpIHATGgBwA&sclient=gws-wiz-serp", "Dr. Eduardo M. Lacap, Jr.")
|
| 136 |
+
)
|
| 137 |
+
),
|
| 138 |
+
|
| 139 |
+
mainPanel(
|
| 140 |
+
tableOutput("table")
|
| 141 |
+
)
|
| 142 |
+
)
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
# Define server logic
|
| 147 |
+
server <- function(input, output, session) {
|
| 148 |
+
|
| 149 |
+
# Reactive expression for the number of attempts
|
| 150 |
+
attempted <- reactive({ input$attempt })
|
| 151 |
+
|
| 152 |
+
# Reactive expression for the nature of the files uploaded
|
| 153 |
+
|
| 154 |
+
independnt <- reactive({input$independent})
|
| 155 |
+
|
| 156 |
+
# Reactive expression to read and combine uploaded Excel files
|
| 157 |
+
combined_df <- reactive({
|
| 158 |
+
req(input$files$datapath) # Ensure files are uploaded
|
| 159 |
+
|
| 160 |
+
df_list <- mapply(function(path, name) {
|
| 161 |
+
df <- read_and_preprocess(path, tools::file_path_sans_ext(basename(name)))
|
| 162 |
+
df <- calculate_additional_columns(df, attempted(), tools::file_path_sans_ext(basename(name)))
|
| 163 |
+
return(df)
|
| 164 |
+
}, input$files$datapath, input$files$name, SIMPLIFY = FALSE)
|
| 165 |
+
|
| 166 |
+
combined_df <- bind_rows(df_list)
|
| 167 |
+
|
| 168 |
+
combined_df <- if (length(df_list) == 1) {
|
| 169 |
+
df_list[[1]]
|
| 170 |
+
} else {
|
| 171 |
+
as.data.frame(combined_df) %>%
|
| 172 |
+
select(ID_Number, Last_Name, starts_with("Average")) %>%
|
| 173 |
+
pivot_longer(cols = starts_with("Average_"), names_to = "Average_Type", values_to = "Average_Value") %>%
|
| 174 |
+
filter(!is.na(Average_Value)) %>%
|
| 175 |
+
pivot_wider(names_from = "Average_Type", values_from = "Average_Value") %>%
|
| 176 |
+
mutate_at(., vars(starts_with("Average_")), ~replace(., is.na(.), 0), values_fn = list) %>%
|
| 177 |
+
mutate(Marks = round(rowMeans(select(., starts_with("Average_")), na.rm = TRUE)+0.1,0))
|
| 178 |
+
}
|
| 179 |
+
return(combined_df)
|
| 180 |
+
})
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
# Display combined data as a table
|
| 184 |
+
output$table <- renderTable({
|
| 185 |
+
combined_df()
|
| 186 |
+
})
|
| 187 |
+
|
| 188 |
+
# Download combined data
|
| 189 |
+
output$downloadData <- downloadHandler(
|
| 190 |
+
filename = function() {
|
| 191 |
+
paste("MarksAggregated_", attempted(), "_MinAttempt.xlsx", sep = "")
|
| 192 |
+
},
|
| 193 |
+
content = function(file) {
|
| 194 |
+
write.xlsx(combined_df(), file)
|
| 195 |
+
}
|
| 196 |
+
)
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
# Run the application
|
| 201 |
+
shinyApp(ui = ui, server = server)
|
app.R
CHANGED
|
@@ -6,8 +6,10 @@ library(stringr)
|
|
| 6 |
library(openxlsx)
|
| 7 |
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
|
|
|
| 11 |
inactivity <- sprintf("
|
| 12 |
function idleTimer() {
|
| 13 |
var t;
|
|
@@ -16,8 +18,9 @@ function idleTimer() {
|
|
| 16 |
// Events that reset the timer
|
| 17 |
var events = ['mousemove', 'mousedown', 'click', 'scroll', 'keypress'];
|
| 18 |
|
| 19 |
-
// Function to log out
|
| 20 |
function logout() {
|
|
|
|
| 21 |
Shiny.setInputValue('timeOut', '%s');
|
| 22 |
}
|
| 23 |
|
|
@@ -36,8 +39,10 @@ function idleTimer() {
|
|
| 36 |
t = setTimeout(logout, timeout);
|
| 37 |
}
|
| 38 |
|
| 39 |
-
// Initialize the idle timer
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
", timeoutSeconds, timeoutSeconds)
|
| 42 |
|
| 43 |
|
|
@@ -166,7 +171,8 @@ server <- function(input, output, session) {
|
|
| 166 |
combined_df <- bind_rows(df_list)
|
| 167 |
|
| 168 |
combined_df <- if (length(df_list) == 1) {
|
| 169 |
-
df_list[[1]]
|
|
|
|
| 170 |
} else {
|
| 171 |
as.data.frame(combined_df) %>%
|
| 172 |
select(ID_Number, Last_Name, starts_with("Average")) %>%
|
|
|
|
| 6 |
library(openxlsx)
|
| 7 |
|
| 8 |
|
| 9 |
+
# Define the timeout period in seconds
|
| 10 |
+
timeoutSeconds <- 120
|
| 11 |
|
| 12 |
+
# Create the JavaScript code to handle user inactivity
|
| 13 |
inactivity <- sprintf("
|
| 14 |
function idleTimer() {
|
| 15 |
var t;
|
|
|
|
| 18 |
// Events that reset the timer
|
| 19 |
var events = ['mousemove', 'mousedown', 'click', 'scroll', 'keypress'];
|
| 20 |
|
| 21 |
+
// Function to log out and notify the user
|
| 22 |
function logout() {
|
| 23 |
+
alert('You have been disconnected due to inactivity. Refresh your browser to use the webapp again. - Dr. Eduardo');
|
| 24 |
Shiny.setInputValue('timeOut', '%s');
|
| 25 |
}
|
| 26 |
|
|
|
|
| 39 |
t = setTimeout(logout, timeout);
|
| 40 |
}
|
| 41 |
|
| 42 |
+
// Initialize the idle timer when the document is ready
|
| 43 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 44 |
+
idleTimer();
|
| 45 |
+
});
|
| 46 |
", timeoutSeconds, timeoutSeconds)
|
| 47 |
|
| 48 |
|
|
|
|
| 171 |
combined_df <- bind_rows(df_list)
|
| 172 |
|
| 173 |
combined_df <- if (length(df_list) == 1) {
|
| 174 |
+
df_list[[1]] %>%
|
| 175 |
+
select(ID_Number, Last_Name, starts_with("Average"))
|
| 176 |
} else {
|
| 177 |
as.data.frame(combined_df) %>%
|
| 178 |
select(ID_Number, Last_Name, starts_with("Average")) %>%
|