Skip to content

Commit e578042

Browse files
Merge pull request #338 from coding-for-reproducible-research/accessibility_iframe
Modifications for WCAG 2.2
2 parents 9e3b817 + 0fc8a94 commit e578042

File tree

53 files changed

+16694
-10634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+16694
-10634
lines changed

R_functions/quiz_renderer.R

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# quiz_renderer.R
2+
3+
# Load required libraries
4+
library(jsonlite)
5+
library(IRdisplay)
6+
library(uuid) # For generating unique quiz IDs
7+
8+
show_quiz_from_json <- function(path, quiz_id_prefix = NULL) {
9+
quiz_data <- fromJSON(path, simplifyVector = FALSE)
10+
11+
# Generate a unique prefix if one isn't supplied
12+
if (is.null(quiz_id_prefix)) {
13+
quiz_id_prefix <- paste0("quiz_", UUIDgenerate(use.time = TRUE))
14+
}
15+
16+
html <- '
17+
<style>
18+
.quiz-question {
19+
background-color: #392061;
20+
color: white;
21+
padding: 12px;
22+
border-radius: 10px;
23+
font-weight: bold;
24+
font-size: 1.2em;
25+
margin-bottom: 10px;
26+
}
27+
28+
.quiz-form {
29+
margin-bottom: 20px;
30+
}
31+
32+
.quiz-answer {
33+
display: block;
34+
background-color: #f2f2f2;
35+
border: none;
36+
border-radius: 10px;
37+
padding: 10px;
38+
margin: 5px 0;
39+
font-size: 1em;
40+
cursor: pointer;
41+
text-align: left;
42+
transition: background-color 0.3s;
43+
width: 100%;
44+
}
45+
46+
.quiz-answer:hover {
47+
background-color: #e0e0e0;
48+
}
49+
50+
.correct {
51+
background-color: #4CAF50 !important;
52+
color: white !important;
53+
border: none;
54+
}
55+
56+
.incorrect {
57+
background-color: #D32F2F !important;
58+
color: white !important;
59+
border: none;
60+
}
61+
62+
.feedback {
63+
margin-top: 10px;
64+
font-weight: bold;
65+
font-size: 1em;
66+
}
67+
</style>
68+
69+
<script>
70+
function handleAnswer(qid, aid, feedback, isCorrect) {
71+
let buttons = document.querySelectorAll("." + qid);
72+
buttons.forEach(btn => {
73+
btn.classList.remove("correct", "incorrect");
74+
});
75+
76+
let selected = document.getElementById(aid);
77+
if (selected) {
78+
selected.classList.add(isCorrect ? "correct" : "incorrect");
79+
}
80+
81+
let feedbackBox = document.getElementById("feedback_" + qid);
82+
if (feedbackBox) {
83+
feedbackBox.innerHTML = feedback;
84+
feedbackBox.style.color = isCorrect ? "green" : "red";
85+
}
86+
}
87+
</script>
88+
'
89+
90+
for (i in seq_along(quiz_data)) {
91+
question <- quiz_data[[i]]
92+
qid <- sprintf("%s_q%s", quiz_id_prefix, i)
93+
html <- paste0(html, sprintf('<div class="quiz-question">%s</div><form class="quiz-form">', question$question))
94+
95+
for (j in seq_along(question$answers)) {
96+
answer <- question$answers[[j]]
97+
aid <- sprintf("%s_a%s", qid, j)
98+
feedback <- gsub("'", "\\'", answer$feedback)
99+
correct <- tolower(substr(answer$feedback, 1, 7)) == "correct"
100+
correct_js <- tolower(as.character(correct))
101+
102+
html <- paste0(html, sprintf(
103+
'<button type="button" class="quiz-answer %s" id="%s"
104+
onclick="handleAnswer(\'%s\', \'%s\', \'%s\', %s)">
105+
%s</button>',
106+
qid, aid, qid, aid, feedback, correct_js, answer$answer
107+
))
108+
}
109+
110+
html <- paste0(html, sprintf(
111+
'<div class="feedback" id="feedback_%s"></div>
112+
<button type="submit" style="position:absolute; left:-9999px; width:1px; height:1px; overflow:hidden;">
113+
Submit
114+
</button>
115+
</form><hr>', qid))
116+
}
117+
118+
display_html(html)
119+
}

individual_modules/advanced_regression_analysis_with_R/advanced_regression_analysis_with_R_extras.ipynb

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 2,
5+
"execution_count": 1,
66
"id": "3bd18871-f159-4905-b82f-df059bc416a3",
77
"metadata": {
88
"editable": true,
@@ -81,7 +81,7 @@
8181
},
8282
{
8383
"cell_type": "code",
84-
"execution_count": 3,
84+
"execution_count": 2,
8585
"id": "4a078d31-2ae4-4215-affe-111c49a4059f",
8686
"metadata": {
8787
"editable": true,
@@ -92,31 +92,32 @@
9292
},
9393
"outputs": [
9494
{
95-
"name": "stdout",
96-
"output_type": "stream",
97-
"text": [
98-
"\n",
99-
"Call:\n",
100-
"lm(formula = CognitionB ~ VisitNum * Sex, data = cogDat)\n",
101-
"\n",
102-
"Residuals:\n",
103-
" Min 1Q Median 3Q Max \n",
104-
"-12.937 -2.827 0.218 2.982 12.064 \n",
105-
"\n",
106-
"Coefficients:\n",
107-
" Estimate Std. Error t value Pr(>|t|) \n",
108-
"(Intercept) 7.7202 0.4353 17.737 < 2e-16 ***\n",
109-
"VisitNum 0.3977 0.1196 3.325 0.000931 ***\n",
110-
"SexM 1.2563 0.6497 1.934 0.053556 . \n",
111-
"VisitNum:SexM -0.4590 0.1858 -2.471 0.013729 * \n",
112-
"---\n",
113-
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
114-
"\n",
115-
"Residual standard error: 4.527 on 693 degrees of freedom\n",
116-
"Multiple R-squared: 0.01617,\tAdjusted R-squared: 0.01192 \n",
117-
"F-statistic: 3.798 on 3 and 693 DF, p-value: 0.01017\n",
118-
"\n"
119-
]
95+
"data": {
96+
"text/plain": [
97+
"\n",
98+
"Call:\n",
99+
"lm(formula = CognitionB ~ VisitNum * Sex, data = cogDat)\n",
100+
"\n",
101+
"Residuals:\n",
102+
" Min 1Q Median 3Q Max \n",
103+
"-11.465 -3.117 0.125 2.918 14.382 \n",
104+
"\n",
105+
"Coefficients:\n",
106+
" Estimate Std. Error t value Pr(>|t|) \n",
107+
"(Intercept) 9.2834 0.5080 18.275 <2e-16 ***\n",
108+
"VisitNum -0.1923 0.1564 -1.230 0.219 \n",
109+
"SexM -0.6392 0.6616 -0.966 0.334 \n",
110+
"VisitNum:SexM -0.0136 0.1999 -0.068 0.946 \n",
111+
"---\n",
112+
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
113+
"\n",
114+
"Residual standard error: 4.262 on 668 degrees of freedom\n",
115+
"Multiple R-squared: 0.01283,\tAdjusted R-squared: 0.008394 \n",
116+
"F-statistic: 2.893 on 3 and 668 DF, p-value: 0.03462\n"
117+
]
118+
},
119+
"metadata": {},
120+
"output_type": "display_data"
120121
}
121122
],
122123
"source": [
@@ -142,7 +143,7 @@
142143
},
143144
{
144145
"cell_type": "code",
145-
"execution_count": 4,
146+
"execution_count": 3,
146147
"id": "4fa1e36f-894a-4b4a-82d8-62a3849ff5a8",
147148
"metadata": {
148149
"editable": true,
@@ -153,30 +154,31 @@
153154
},
154155
"outputs": [
155156
{
156-
"name": "stdout",
157-
"output_type": "stream",
158-
"text": [
159-
"\n",
160-
"Call:\n",
161-
"lm(formula = CognitionB ~ VisitNum:Sex, data = cogDat)\n",
162-
"\n",
163-
"Residuals:\n",
164-
" Min 1Q Median 3Q Max \n",
165-
"-12.7225 -2.9448 0.2117 3.0424 11.6298 \n",
166-
"\n",
167-
"Coefficients:\n",
168-
" Estimate Std. Error t value Pr(>|t|) \n",
169-
"(Intercept) 8.28413 0.32378 25.585 < 2e-16 ***\n",
170-
"VisitNum:SexF 0.26797 0.09922 2.701 0.00709 ** \n",
171-
"VisitNum:SexM 0.11395 0.10974 1.038 0.29946 \n",
172-
"---\n",
173-
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
174-
"\n",
175-
"Residual standard error: 4.536 on 694 degrees of freedom\n",
176-
"Multiple R-squared: 0.01087,\tAdjusted R-squared: 0.008016 \n",
177-
"F-statistic: 3.812 on 2 and 694 DF, p-value: 0.02257\n",
178-
"\n"
179-
]
157+
"data": {
158+
"text/plain": [
159+
"\n",
160+
"Call:\n",
161+
"lm(formula = CognitionB ~ VisitNum:Sex, data = cogDat)\n",
162+
"\n",
163+
"Residuals:\n",
164+
" Min 1Q Median 3Q Max \n",
165+
"-11.5941 -3.1624 0.1885 2.9499 14.5579 \n",
166+
"\n",
167+
"Coefficients:\n",
168+
" Estimate Std. Error t value Pr(>|t|) \n",
169+
"(Intercept) 8.90655 0.32541 27.370 < 2e-16 ***\n",
170+
"VisitNum:SexF -0.09198 0.11687 -0.787 0.43155 \n",
171+
"VisitNum:SexM -0.27235 0.10386 -2.622 0.00894 ** \n",
172+
"---\n",
173+
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
174+
"\n",
175+
"Residual standard error: 4.262 on 669 degrees of freedom\n",
176+
"Multiple R-squared: 0.01145,\tAdjusted R-squared: 0.008493 \n",
177+
"F-statistic: 3.874 on 2 and 669 DF, p-value: 0.02125\n"
178+
]
179+
},
180+
"metadata": {},
181+
"output_type": "display_data"
180182
}
181183
],
182184
"source": [
@@ -200,7 +202,7 @@
200202
},
201203
{
202204
"cell_type": "code",
203-
"execution_count": 5,
205+
"execution_count": 4,
204206
"id": "ca2c5012-a2c2-4e7e-ac5b-75ffcfec49ae",
205207
"metadata": {
206208
"editable": true,
@@ -211,31 +213,32 @@
211213
},
212214
"outputs": [
213215
{
214-
"name": "stdout",
215-
"output_type": "stream",
216-
"text": [
217-
"\n",
218-
"Call:\n",
219-
"lm(formula = CognitionB ~ Sex + VisitNum:Sex, data = cogDat)\n",
220-
"\n",
221-
"Residuals:\n",
222-
" Min 1Q Median 3Q Max \n",
223-
"-12.937 -2.827 0.218 2.982 12.064 \n",
224-
"\n",
225-
"Coefficients:\n",
226-
" Estimate Std. Error t value Pr(>|t|) \n",
227-
"(Intercept) 7.72023 0.43527 17.737 < 2e-16 ***\n",
228-
"SexM 1.25633 0.64970 1.934 0.053556 . \n",
229-
"SexF:VisitNum 0.39774 0.11962 3.325 0.000931 ***\n",
230-
"SexM:VisitNum -0.06122 0.14213 -0.431 0.666781 \n",
231-
"---\n",
232-
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
233-
"\n",
234-
"Residual standard error: 4.527 on 693 degrees of freedom\n",
235-
"Multiple R-squared: 0.01617,\tAdjusted R-squared: 0.01192 \n",
236-
"F-statistic: 3.798 on 3 and 693 DF, p-value: 0.01017\n",
237-
"\n"
238-
]
216+
"data": {
217+
"text/plain": [
218+
"\n",
219+
"Call:\n",
220+
"lm(formula = CognitionB ~ Sex + VisitNum:Sex, data = cogDat)\n",
221+
"\n",
222+
"Residuals:\n",
223+
" Min 1Q Median 3Q Max \n",
224+
"-11.465 -3.117 0.125 2.918 14.382 \n",
225+
"\n",
226+
"Coefficients:\n",
227+
" Estimate Std. Error t value Pr(>|t|) \n",
228+
"(Intercept) 9.2834 0.5080 18.275 <2e-16 ***\n",
229+
"SexM -0.6392 0.6616 -0.966 0.3343 \n",
230+
"SexF:VisitNum -0.1923 0.1564 -1.230 0.2191 \n",
231+
"SexM:VisitNum -0.2059 0.1245 -1.654 0.0987 . \n",
232+
"---\n",
233+
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
234+
"\n",
235+
"Residual standard error: 4.262 on 668 degrees of freedom\n",
236+
"Multiple R-squared: 0.01283,\tAdjusted R-squared: 0.008394 \n",
237+
"F-statistic: 2.893 on 3 and 668 DF, p-value: 0.03462\n"
238+
]
239+
},
240+
"metadata": {},
241+
"output_type": "display_data"
239242
}
240243
],
241244
"source": [

0 commit comments

Comments
 (0)