-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.R
More file actions
159 lines (135 loc) · 4.72 KB
/
app.R
File metadata and controls
159 lines (135 loc) · 4.72 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
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
# app.R - Quiz Landing Page for openwashdata Course
library(shiny)
library(bslib)
library(yaml)
# Load configuration
source("config.R")
# Function to extract quiz metadata from Rmd files
extract_quiz_metadata <- function(quiz_name) {
rmd_path <- file.path("modules", paste0(quiz_name, ".Rmd"))
if (!file.exists(rmd_path)) {
return(NULL)
}
# Read the Rmd file and extract YAML header
rmd_content <- readLines(rmd_path)
yaml_start <- which(rmd_content == "---")[1]
yaml_end <- which(rmd_content == "---")[2]
if (is.na(yaml_start) || is.na(yaml_end) || yaml_start >= yaml_end) {
return(NULL)
}
yaml_content <- paste(rmd_content[(yaml_start + 1):(yaml_end - 1)], collapse = "\n")
yaml_data <- yaml::yaml.load(yaml_content)
# Extract title and description
title <- yaml_data$title %||% paste("Quiz:", quiz_name)
description <- yaml_data$description %||% "Interactive quiz module"
return(list(title = title, description = description))
}
# Auto-generate quiz list from quiz names
generate_quiz_list <- function(quiz_names) {
# Generate quiz list with metadata
quiz_list <- lapply(quiz_names, function(quiz_name) {
metadata <- extract_quiz_metadata(quiz_name)
# Generate URL based on quiz name
quiz_url <- paste0(base_url, quiz_name, "/")
list(
id = quiz_name,
title = metadata$title %||% paste("Quiz:", quiz_name),
description = metadata$description %||% "Interactive quiz module",
url = quiz_url,
available = TRUE
)
})
return(quiz_list)
}
# Generate quiz list automatically from config
quizzes <- generate_quiz_list(quiz_names)
# UI
ui <- page_navbar(
title = "openwashdata Quizzes",
theme = bs_theme(bootswatch = "cosmo"),
nav_panel(
"Home",
div(
class = "container mt-5",
div(
class = "text-center mb-5",
h1("openwashdata Course Quizzes"),
p(class = "lead", "Interactive tutorials to test your knowledge")
),
div(
class = "row justify-content-center",
div(
class = "col-md-8",
lapply(seq_along(quizzes), function(i) {
quiz <- quizzes[[i]]
div(
class = "card mb-4",
div(
class = "card-header d-flex justify-content-between align-items-center",
h4(class = "mb-0", quiz$title),
if (!quiz$available) {
span(class = "badge bg-secondary", "Coming Soon")
}
),
div(
class = "card-body",
p(quiz$description),
if (quiz$available) {
tags$a(
href = quiz$url,
target = "_blank",
class = "btn btn-primary btn-lg",
"Start Quiz"
)
} else {
span(class = "text-muted", "This quiz is not yet available")
}
)
)
})
)
)
)
),
nav_panel(
"About",
div(
class = "container mt-5",
div(
class = "row justify-content-center",
div(
class = "col-md-8",
h2("About These Quizzes"),
p("These interactive quizzes are designed to help you learn and practice concepts from the openwashdata course."),
h3("Features"),
tags$ul(
tags$li("Interactive R code exercises"),
tags$li("Immediate feedback on your answers"),
tags$li("Hints and solutions available"),
tags$li("Progress tracking within each quiz"),
tags$li("Automatic grading with gradethis")
),
h3("How to Use"),
tags$ol(
tags$li("Select a quiz module from the home page"),
tags$li("Click 'Start Quiz' to open the interactive tutorial"),
tags$li("Work through the questions at your own pace"),
tags$li("Run code in the interactive exercises"),
tags$li("Use hints if you get stuck"),
tags$li("Check your solutions for immediate feedback")
),
h3("Technical Requirements"),
p("These quizzes run entirely in your web browser. No R installation is required on your computer - everything runs on our servers."),
h3("Progress Tracking"),
p("Your progress is automatically saved within each quiz session. However, progress may be lost if you close the browser or if the session times out.")
)
)
)
)
)
# Server
server <- function(input, output, session) {
# Simple server - no reactive elements needed for this landing page
}
# Create Shiny app
shinyApp(ui = ui, server = server)