-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.html
3307 lines (2892 loc) · 130 KB
/
stat.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.4.554">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>DAiR Workshop 2024</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./USL.html" rel="next">
<link href="./datatype.html" rel="prev">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 50,
"keyboard-shortcut": [
"f",
"/",
"s"
],
"show-item-context": false,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-text-placeholder": "",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<script src="site_libs/kePrint-0.0.1/kePrint.js"></script>
<link href="site_libs/lightable-0.0.1/lightable.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/editor/editor.main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<style type="text/css">
.monaco-editor pre {
background-color: unset !important;
}
.qwebr-editor-toolbar {
width: 100%;
display: flex;
justify-content: space-between;
box-sizing: border-box;
}
.qwebr-editor-toolbar-left-buttons, .qwebr-editor-toolbar-right-buttons {
display: flex;
}
.qwebr-non-interactive-loading-container.qwebr-cell-needs-evaluation, .qwebr-non-interactive-loading-container.qwebr-cell-evaluated {
justify-content: center;
display: flex;
background-color: rgba(250, 250, 250, 0.65);
border: 1px solid rgba(233, 236, 239, 0.65);
border-radius: 0.5rem;
margin-top: 15px;
margin-bottom: 15px;
}
.qwebr-r-project-logo {
color: #2767B0; /* R Project's blue color */
}
.qwebr-icon-status-spinner {
color: #7894c4;
}
.qwebr-icon-run-code {
color: #0d9c29
}
body.quarto-light .qwebr-output-code-stdout {
color: #111;
}
body.quarto-dark .qwebr-output-code-stdout {
color: #EEE;
}
.qwebr-output-code-stderr {
color: #db4133;
}
body.quarto-light .qwebr-editor {
border: 1px solid #EEEEEE;
}
body.quarto-light .qwebr-editor-toolbar {
background-color: #EEEEEE;
padding: 0.2rem 0.5rem;
}
body.quarto-dark .qwebr-editor {
border: 1px solid #111;
}
body.quarto-dark .qwebr-editor-toolbar {
background-color: #111;
padding: 0.2rem 0.5rem;
}
.qwebr-button {
display: inline-block;
font-weight: 400;
line-height: 1;
text-decoration: none;
text-align: center;
padding: 0.375rem 0.75rem;
font-size: .9rem;
border-radius: 0.25rem;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
body.quarto-light .qwebr-button {
background-color: #EEEEEE;
color: #000;
border-color: #dee2e6;
border: 1px solid rgba(0,0,0,0);
}
body.quarto-dark .qwebr-button {
background-color: #111;
color: #EEE;
border-color: #dee2e6;
border: 1px solid rgba(0,0,0,0);
}
body.quarto-light .qwebr-button:hover {
color: #000;
background-color: #d9dce0;
border-color: #c8ccd0;
}
body.quarto-dark .qwebr-button:hover {
color: #d9dce0;
background-color: #323232;
border-color: #d9dce0;
}
.qwebr-button:disabled,.qwebr-button.disabled,fieldset:disabled .qwebr-button {
pointer-events: none;
opacity: .65
}
.qwebr-button-reset {
color: #696969; /*#4682b4;*/
}
.qwebr-button-copy {
color: #696969;
}
/* Style the code highlight lines */
body.quarto-light .qwebr-editor-highlight-line {
background-color: lightblue;
}
body.quarto-dark .qwebr-editor-highlight-line {
background-color: darkblue;
}
/* Style the modal pop-up */
/* The Modal (background) */
.qwebr-modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 60px;
}
/* Modal Content */
.qwebr-modal-content {
background-color: #fefefe;
margin: 5% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
.qwebr-modal-content-code {
max-height: 50vh;
min-height: 5vh;
overflow: scroll;
border: 1px solid #888;
}
/* The Close Button */
.qwebr-modal-close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.qwebr-modal-close:hover,
.qwebr-modal-close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.qwebr-download-btn {
margin-top: 10px;
text-decoration: none !important;
}
/* Styling to download image that is created */
.qwebr-canvas-image {
position: relative;
display: inline-block;
margin: 10px;
}
.qwebr-canvas-image-download-btn {
position: absolute;
top: 10px;
right: 10px;
padding: 5px 10px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
display: none;
}
figure:hover .qwebr-canvas-image-download-btn {
display: block;
}
/* Custom styling for RevealJS Presentations*/
/* Reset the style of the interactive area */
.reveal div.qwebr-interactive-area {
display: block;
box-shadow: none;
max-width: 100%;
max-height: 100%;
margin: 0;
padding: 0;
}
/* Provide space to entries */
.reveal div.qwebr-output-code-area pre div {
margin: 1px 2px 1px 10px;
}
/* Collapse the inside code tags to avoid extra space between line outputs */
.reveal pre div code.qwebr-output-code-stdout, .reveal pre div code.qwebr-output-code-stderr {
padding: 0;
display: contents;
}
body.reveal.quarto-light pre div code.qwebr-output-code-stdout {
color: #111;
}
body.reveal.quarto-dark pre div code.qwebr-output-code-stdout {
color: #EEEEEE;
}
.reveal pre div code.qwebr-output-code-stderr {
color: #db4133;
}
/* Create a border around console and output (does not effect graphs) */
body.reveal.quarto-light div.qwebr-console-area {
border: 1px solid #EEEEEE;
box-shadow: 2px 2px 10px #EEEEEE;
}
body.reveal.quarto-dark div.qwebr-console-area {
border: 1px solid #111;
box-shadow: 2px 2px 10px #111;
}
/* Cap output height and allow text to scroll */
/* TODO: Is there a better way to fit contents/max it parallel to the monaco editor size? */
.reveal div.qwebr-output-code-area pre {
max-height: 400px;
overflow: scroll;
}
</style>
<script type="module">
// Document level settings ----
// Determine if we need to install R packages
globalThis.qwebrInstallRPackagesList = ['BiocManager', 'ggplot2', 'dplyr', 'ibr', 'rstudioapi', 'DiagrammeR', 'data.tree', 'shiny', 'ARTofR', 'rgl', 'phytools', 'ape', 'pkgnet', 'tidyverse', 'magrittr', 'rcmdcheck'];
// Specify possible locations to search for the repository
globalThis.qwebrPackageRepoURLS = ['https://repo.r-wasm.org/'];
// Check to see if we have an empty array, if we do set to skip the installation.
globalThis.qwebrSetupRPackages = !(qwebrInstallRPackagesList.indexOf("") !== -1);
globalThis.qwebrAutoloadRPackages = true;
// Display a startup message?
globalThis.qwebrShowStartupMessage = true;
globalThis.qwebrShowHeaderMessage = false;
// Describe the webR settings that should be used
globalThis.qwebrCustomizedWebROptions = {
"baseURL": "https://webr.r-wasm.org/v0.3.3/",
"serviceWorkerUrl": "",
"homedir": "/home/web_user",
"channelType": "ChannelType.Automatic"
};
// Store cell data
globalThis.qwebrCellDetails = [{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-1","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"pnorm(1.96)\n#To find a two-tailed area (corresponding to a 2-tailed p-value) for a positive z-value\n2*(1-pnorm(1.96))","id":1},{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-2","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"qnorm(.05)","id":2},{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-3","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"pt(2.50,25)\n#To find a two-tailed p-value for a positive t-value:\n2*(1-pt(2.50,25))","id":3},{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-4","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"qt(.05,25)\n#To find the critical t-value for a 95% confidence interval with 25 degrees freedom:\nqt(1-.05/2,25)","id":4},{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-5","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"pchisq(3.84,1)\n#For the chi-square test, we are usually interested in upper-tail areas as p-values. To find the p-value corresponding to a chi-square value of 4.50 with 1 d.f.:\n1-pchisq(4.50,1)","id":5},{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-6","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"library(ggplot2)\nmsleep\nclass(msleep)\ntypeof(msleep)\nhead(msleep)\ntail(msleep)\ndim(msleep)\nstr(msleep)\nnames(msleep)\nsummary(msleep)\nmean(msleep$sleep_total)# Mean\nmedian(msleep$sleep_total)# Median\nquantile(msleep$sleep_total)# Various quantiles\nlength(msleep$sleep_total)\nmax(msleep$sleep_total)# Max\nmin(msleep$sleep_total)# Min\nsd(msleep$sleep_total)# Standard deviation\nvar(msleep$sleep_total)# Variance\nsum(msleep$sleep_total > 8)# Frequency (count)\nmean(msleep$sleep_total > 8)# Relative frequency (proportion)\nmean(msleep$sleep_rem)\nmean(msleep$sleep_rem, na.rm = TRUE)\ncor(msleep$sleep_total, msleep$sleep_rem)\ncor(msleep$sleep_total, msleep$sleep_rem, use = \"complete.obs\")\ncummax(msleep$sleep_total) ","id":6},{"options":{"out-height":"","comment":"","message":"true","editor-quick-suggestions":"false","warning":"true","label":"unnamed-chunk-7","fig-width":7,"autorun":"false","read-only":"false","output":"true","results":"markup","dpi":72,"out-width":"700px","fig-height":5,"context":"interactive","fig-cap":"","editor-word-wrap":"true","classes":"","editor-max-height":"","editor-font-scale":"1"},"code":"library(ggplot2)\ntable(msleep$vore)\nproportions(table(msleep$vore))#To instead show the proportion of different categories\n# Counts:\ntable(msleep$vore, msleep$conservation)\n# Proportions, per row:\nproportions(table(msleep$vore, msleep$conservation),margin = 1)\n# Proportions, per column:\nproportions(table(msleep$vore, msleep$conservation),\nmargin = 2)\n# Proportions, out of total:\nproportions(table(msleep$vore, msleep$conservation))","id":7}];
</script>
<script type="module">
// Declare startupMessageQWebR globally
globalThis.qwebrStartupMessage = document.createElement("p");
// Verify if OffScreenCanvas is supported
globalThis.qwebrOffScreenCanvasSupport = function() {
return typeof OffscreenCanvas !== 'undefined'
}
// Function to set the button text
globalThis.qwebrSetInteractiveButtonState = function(buttonText, enableCodeButton = true) {
document.querySelectorAll(".qwebr-button-run").forEach((btn) => {
btn.innerHTML = buttonText;
btn.disabled = !enableCodeButton;
});
}
// Function to update the status message in non-interactive cells
globalThis.qwebrUpdateStatusMessage = function(message) {
document.querySelectorAll(".qwebr-status-text.qwebr-cell-needs-evaluation").forEach((elem) => {
elem.innerText = message;
});
}
// Function to update the status message
globalThis.qwebrUpdateStatusHeader = function(message) {
qwebrStartupMessage.innerHTML = `
<i class="fa-solid fa-spinner fa-spin qwebr-icon-status-spinner"></i>
<span>${message}</span>`;
}
// Function to return true if element is found, false if not
globalThis.qwebrCheckHTMLElementExists = function(selector) {
const element = document.querySelector(selector);
return !!element;
}
// Function that detects whether reveal.js slides are present
globalThis.qwebrIsRevealJS = function() {
// If the '.reveal .slides' selector exists, RevealJS is likely present
return qwebrCheckHTMLElementExists('.reveal .slides');
}
// Initialize the Quarto sidebar element
function qwebrSetupQuartoSidebar() {
var newSideBarDiv = document.createElement('div');
newSideBarDiv.id = 'quarto-margin-sidebar';
newSideBarDiv.className = 'sidebar margin-sidebar';
newSideBarDiv.style.top = '0px';
newSideBarDiv.style.maxHeight = 'calc(0px + 100vh)';
return newSideBarDiv;
}
// Position the sidebar in the document
function qwebrPlaceQuartoSidebar() {
// Get the reference to the element with id 'quarto-document-content'
var referenceNode = document.getElementById('quarto-document-content');
// Create the new div element
var newSideBarDiv = qwebrSetupQuartoSidebar();
// Insert the new div before the 'quarto-document-content' element
referenceNode.parentNode.insertBefore(newSideBarDiv, referenceNode);
}
function qwebrPlaceMessageContents(content, html_location = "title-block-header", revealjs_location = "title-slide") {
// Get references to header elements
const headerHTML = document.getElementById(html_location);
const headerRevealJS = document.getElementById(revealjs_location);
// Determine where to insert the quartoTitleMeta element
if (headerHTML || headerRevealJS) {
// Append to the existing "title-block-header" element or "title-slide" div
(headerHTML || headerRevealJS).appendChild(content);
} else {
// If neither headerHTML nor headerRevealJS is found, insert after "webr-monaco-editor-init" script
const monacoScript = document.getElementById("qwebr-monaco-editor-init");
const header = document.createElement("header");
header.setAttribute("id", "title-block-header");
header.appendChild(content);
monacoScript.after(header);
}
}
function qwebrOffScreenCanvasSupportWarningMessage() {
// Verify canvas is supported.
if(qwebrOffScreenCanvasSupport()) return;
// Create the main container div
var calloutContainer = document.createElement('div');
calloutContainer.classList.add('callout', 'callout-style-default', 'callout-warning', 'callout-titled');
// Create the header div
var headerDiv = document.createElement('div');
headerDiv.classList.add('callout-header', 'd-flex', 'align-content-center');
// Create the icon container div
var iconContainer = document.createElement('div');
iconContainer.classList.add('callout-icon-container');
// Create the icon element
var iconElement = document.createElement('i');
iconElement.classList.add('callout-icon');
// Append the icon element to the icon container
iconContainer.appendChild(iconElement);
// Create the title container div
var titleContainer = document.createElement('div');
titleContainer.classList.add('callout-title-container', 'flex-fill');
titleContainer.innerText = 'Warning: Web Browser Does Not Support Graphing!';
// Append the icon container and title container to the header div
headerDiv.appendChild(iconContainer);
headerDiv.appendChild(titleContainer);
// Create the body container div
var bodyContainer = document.createElement('div');
bodyContainer.classList.add('callout-body-container', 'callout-body');
// Create the paragraph element for the body content
var paragraphElement = document.createElement('p');
paragraphElement.innerHTML = 'This web browser does not have support for displaying graphs through the <code>quarto-webr</code> extension since it lacks an <code>OffScreenCanvas</code>. Please upgrade your web browser to one that supports <code>OffScreenCanvas</code>.';
// Append the paragraph element to the body container
bodyContainer.appendChild(paragraphElement);
// Append the header div and body container to the main container div
calloutContainer.appendChild(headerDiv);
calloutContainer.appendChild(bodyContainer);
// Append the main container div to the document depending on format
qwebrPlaceMessageContents(calloutContainer, "title-block-header");
}
// Function that attaches the document status message and diagnostics
function displayStartupMessage(showStartupMessage, showHeaderMessage) {
if (!showStartupMessage) {
return;
}
// Create the outermost div element for metadata
const quartoTitleMeta = document.createElement("div");
quartoTitleMeta.classList.add("quarto-title-meta");
// Create the first inner div element
const firstInnerDiv = document.createElement("div");
firstInnerDiv.setAttribute("id", "qwebr-status-message-area");
// Create the second inner div element for "WebR Status" heading and contents
const secondInnerDiv = document.createElement("div");
secondInnerDiv.setAttribute("id", "qwebr-status-message-title");
secondInnerDiv.classList.add("quarto-title-meta-heading");
secondInnerDiv.innerText = "WebR Status";
// Create another inner div for contents
const secondInnerDivContents = document.createElement("div");
secondInnerDivContents.setAttribute("id", "qwebr-status-message-body");
secondInnerDivContents.classList.add("quarto-title-meta-contents");
// Describe the WebR state
qwebrStartupMessage.innerText = "🟡 Loading...";
qwebrStartupMessage.setAttribute("id", "qwebr-status-message-text");
// Add `aria-live` to auto-announce the startup status to screen readers
qwebrStartupMessage.setAttribute("aria-live", "assertive");
// Append the startup message to the contents
secondInnerDivContents.appendChild(qwebrStartupMessage);
// Add a status indicator for COOP and COEP Headers if needed
if (showHeaderMessage) {
const crossOriginMessage = document.createElement("p");
crossOriginMessage.innerText = `${crossOriginIsolated ? '🟢' : '🟡'} COOP & COEP Headers`;
crossOriginMessage.setAttribute("id", "qwebr-coop-coep-header");
secondInnerDivContents.appendChild(crossOriginMessage);
}
// Combine the inner divs and contents
firstInnerDiv.appendChild(secondInnerDiv);
firstInnerDiv.appendChild(secondInnerDivContents);
quartoTitleMeta.appendChild(firstInnerDiv);
// Place message on webpage
qwebrPlaceMessageContents(quartoTitleMeta);
}
function qwebrAddCommandHistoryModal() {
// Create the modal div
var modalDiv = document.createElement('div');
modalDiv.id = 'qwebr-history-modal';
modalDiv.className = 'qwebr-modal';
// Create the modal content div
var modalContentDiv = document.createElement('div');
modalContentDiv.className = 'qwebr-modal-content';
// Create the span for closing the modal
var closeSpan = document.createElement('span');
closeSpan.id = 'qwebr-command-history-close-btn';
closeSpan.className = 'qwebr-modal-close';
closeSpan.innerHTML = '×';
// Create the h1 element for the modal
var modalH1 = document.createElement('h1');
modalH1.textContent = 'R History Command Contents';
// Create an anchor element for downloading the Rhistory file
var downloadLink = document.createElement('a');
downloadLink.href = '#';
downloadLink.id = 'qwebr-download-history-btn';
downloadLink.className = 'qwebr-download-btn';
// Create an 'i' element for the icon
var icon = document.createElement('i');
icon.className = 'bi bi-file-code';
// Append the icon to the anchor element
downloadLink.appendChild(icon);
// Add the text 'Download R History' to the anchor element
downloadLink.appendChild(document.createTextNode(' Download R History File'));
// Create the pre for command history contents
var commandContentsPre = document.createElement('pre');
commandContentsPre.id = 'qwebr-command-history-contents';
commandContentsPre.className = 'qwebr-modal-content-code';
// Append the close span, h1, and history contents pre to the modal content div
modalContentDiv.appendChild(closeSpan);
modalContentDiv.appendChild(modalH1);
modalContentDiv.appendChild(downloadLink);
modalContentDiv.appendChild(commandContentsPre);
// Append the modal content div to the modal div
modalDiv.appendChild(modalContentDiv);
// Append the modal div to the body
document.body.appendChild(modalDiv);
}
function qwebrRegisterRevealJSCommandHistoryModal() {
// Select the <ul> element inside the <div> with data-panel="Custom0"
let ulElement = document.querySelector('div[data-panel="Custom0"] > ul.slide-menu-items');
// Find the last <li> element with class slide-tool-item
let lastItem = ulElement.querySelector('li.slide-tool-item:last-child');
// Calculate the next data-item value
let nextItemValue = 0;
if (lastItem) {
nextItemValue = parseInt(lastItem.dataset.item) + 1;
}
// Create a new <li> element
let newListItem = document.createElement('li');
newListItem.className = 'slide-tool-item';
newListItem.dataset.item = nextItemValue.toString(); // Set the next available data-item value
// Create the <a> element inside the <li>
let newLink = document.createElement('a');
newLink.href = '#';
newLink.id = 'qwebrRHistoryButton'; // Set the ID for the new link
// Create the <kbd> element inside the <a>
let newKbd = document.createElement('kbd');
newKbd.textContent = ' '; // Set to empty as we are not registering a keyboard shortcut
// Create text node for the link text
let newText = document.createTextNode(' View R History');
// Append <kbd> and text node to <a>
newLink.appendChild(newKbd);
newLink.appendChild(newText);
// Append <a> to <li>
newListItem.appendChild(newLink);
// Append <li> to <ul>
ulElement.appendChild(newListItem);
}
// Handle setting up the R history modal
function qwebrCodeLinks() {
if (qwebrIsRevealJS()) {
qwebrRegisterRevealJSCommandHistoryModal();
return;
}
// Create the container div
var containerDiv = document.createElement('div');
containerDiv.className = 'quarto-code-links';
// Create the h2 element
var h2 = document.createElement('h2');
h2.textContent = 'webR Code Links';
// Create the ul element
var ul = document.createElement('ul');
// Create the li element
var li = document.createElement('li');
// Create the a_history_btn element
var a_history_btn = document.createElement('a');
a_history_btn.href = 'javascript:void(0)';
a_history_btn.setAttribute('id', 'qwebrRHistoryButton');
// Create the i_history_btn element
var i_history_btn = document.createElement('i');
i_history_btn.className = 'bi bi-file-code';
// Create the text node for the link text
var text_history_btn = document.createTextNode('View R History');
// Append the icon element and link text to the a element
a_history_btn.appendChild(i_history_btn);
a_history_btn.appendChild(text_history_btn);
// Append the a element to the li element
li.appendChild(a_history_btn);
// Append the li element to the ul element
ul.appendChild(li);
// Append the h2 and ul elements to the container div
containerDiv.appendChild(h2);
containerDiv.appendChild(ul);
// Append the container div to the element with the ID 'quarto-margin-sidebar'
var sidebar = document.getElementById('quarto-margin-sidebar');
// If the sidebar element is not found, create it
if(!sidebar) {
qwebrPlaceQuartoSidebar();
}
// Re-select the sidebar element (if it was just created)
sidebar = document.getElementById('quarto-margin-sidebar');
// If the sidebar element exists, append the container div to it
if(sidebar) {
// Append the container div to the sidebar
sidebar.appendChild(containerDiv);
// Force the sidebar to be clickable by removing the 'zindex-bottom' class
// added in pre-release: https://github.com/quarto-dev/quarto-cli/commit/f0c53a1ffcaa1de4eccbf07803b096898248adcc
sidebar.className = 'sidebar margin-sidebar';
} else {
// Get a debugger ...
console.warn('Element with ID "quarto-margin-sidebar" not found.');
}
}
// Call the function to append the code links for qwebR into the right sidebar
qwebrCodeLinks();
// Add the command history modal
qwebrAddCommandHistoryModal();
displayStartupMessage(qwebrShowStartupMessage, qwebrShowHeaderMessage);
qwebrOffScreenCanvasSupportWarningMessage();
</script>
<script type="module">
// Define a global storage and retrieval solution ----
// Store commands executed in R
globalThis.qwebrRCommandHistory = [];
// Function to retrieve the command history
globalThis.qwebrFormatRHistory = function() {
return qwebrRCommandHistory.join("\n\n");
}
// Retrieve HTML Elements ----
// Get the command modal
const command_history_modal = document.getElementById("qwebr-history-modal");
// Get the button that opens the command modal
const command_history_btn = document.getElementById("qwebrRHistoryButton");
// Get the <span> element that closes the command modal
const command_history_close_span = document.getElementById("qwebr-command-history-close-btn");
// Get the download button for r history information
const command_history_download_btn = document.getElementById("qwebr-download-history-btn");
// Plug in command history into modal/download button ----
// Function to populate the modal with command history
function populateCommandHistoryModal() {
document.getElementById("qwebr-command-history-contents").innerHTML = qwebrFormatRHistory() || "No commands have been executed yet.";
}
// Function to format the current date and time to
// a string with the format YYYY-MM-DD-HH-MM-SS
function formatDateTime() {
const now = new Date();
const year = now.getFullYear();
const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}`;
}
// Function to convert document title with datetime to a safe filename
function safeFileName() {
// Get the current page title
let pageTitle = document.title;
// Combine the current page title with the current date and time
let pageNameWithDateTime = `Rhistory-${pageTitle}-${formatDateTime()}`;
// Replace unsafe characters with safe alternatives
let safeFilename = pageNameWithDateTime.replace(/[\\/:\*\?! "<>\|]/g, '-');
return safeFilename;
}
// Function to download list contents as text file
function downloadRHistory() {
// Get the current page title + datetime and use it as the filename
const filename = `${safeFileName()}.R`;
// Get the text contents of the R History list
const text = qwebrFormatRHistory();
// Create a new Blob object with the text contents
const blob = new Blob([text], { type: 'text/plain' });
// Create a new anchor element for the download
const a = document.createElement('a');
a.style.display = 'none';
a.href = URL.createObjectURL(blob);
a.download = filename;
// Append the anchor to the body, click it, and remove it
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
// Register event handlers ----
// When the user clicks the View R History button, open the command modal
command_history_btn.onclick = function() {
populateCommandHistoryModal();
command_history_modal.style.display = "block";
}
// When the user clicks on <span> (x), close the command modal
command_history_close_span.onclick = function() {
command_history_modal.style.display = "none";
}
// When the user clicks anywhere outside of the command modal, close it
window.onclick = function(event) {
if (event.target == command_history_modal) {
command_history_modal.style.display = "none";
}
}
// Add an onclick event listener to the download button so that
// the user can download the R history as a text file
command_history_download_btn.onclick = function() {
downloadRHistory();
};
</script>
<script type="module">
// Supported Evaluation Types for Context
globalThis.EvalTypes = Object.freeze({
Interactive: 'interactive',
Setup: 'setup',
Output: 'output',
});
// Function that obtains the font size for a given element
globalThis.qwebrCurrentFontSizeOnElement = function(element, cssProperty = 'font-size') {
const currentFontSize = parseFloat(
window
.getComputedStyle(element)
.getPropertyValue(cssProperty)
);
return currentFontSize;
}
// Function to determine font scaling
globalThis.qwebrScaledFontSize = function(div, qwebrOptions) {
// Determine if we should compute font-size using RevealJS's `--r-main-font-size`
// or if we can directly use the document's `font-size`.
const cssProperty = document.body.classList.contains('reveal') ?
"--r-main-font-size" : "font-size";
// Get the current font size on the div element
const elementFontSize = qwebrCurrentFontSizeOnElement(div, cssProperty);
// Determine the scaled font size value
const scaledFontSize = ((qwebrOptions['editor-font-scale'] ?? 1) * elementFontSize) ?? 17.5;
return scaledFontSize;
}
// Function that dispatches the creation request
globalThis.qwebrCreateHTMLElement = function (
cellData
) {
// Extract key components
const evalType = cellData.options.context;
const qwebrCounter = cellData.id;
// We make an assumption that insertion points are defined by the Lua filter as:
// qwebr-insertion-location-{qwebrCounter}
const elementLocator = document.getElementById(`qwebr-insertion-location-${qwebrCounter}`);
// Figure out the routine to use to insert the element.
let qwebrElement;
switch ( evalType ) {
case EvalTypes.Interactive:
qwebrElement = qwebrCreateInteractiveElement(qwebrCounter, cellData.options);
break;
case EvalTypes.Output:
qwebrElement = qwebrCreateNonInteractiveOutputElement(qwebrCounter, cellData.options);
break;
case EvalTypes.Setup:
qwebrElement = qwebrCreateNonInteractiveSetupElement(qwebrCounter, cellData.options);
break;
default:
qwebrElement = document.createElement('div');
qwebrElement.textContent = 'Error creating `quarto-webr` element';
}
// Insert the dynamically generated object at the document location.
elementLocator.appendChild(qwebrElement);
};
// Function that setups the interactive element creation
globalThis.qwebrCreateInteractiveElement = function (qwebrCounter, qwebrOptions) {
// Create main div element
var mainDiv = document.createElement('div');
mainDiv.id = 'qwebr-interactive-area-' + qwebrCounter;
mainDiv.className = `qwebr-interactive-area`;
if (qwebrOptions.classes) {
mainDiv.className += " " + qwebrOptions.classes
}
// Add a unique cell identifier that users can customize
if (qwebrOptions.label) {
mainDiv.setAttribute('data-id', qwebrOptions.label);
}
// Create toolbar div
var toolbarDiv = document.createElement('div');
toolbarDiv.className = 'qwebr-editor-toolbar';
toolbarDiv.id = 'qwebr-editor-toolbar-' + qwebrCounter;
// Create a div to hold the left buttons
var leftButtonsDiv = document.createElement('div');
leftButtonsDiv.className = 'qwebr-editor-toolbar-left-buttons';
// Create a div to hold the right buttons
var rightButtonsDiv = document.createElement('div');
rightButtonsDiv.className = 'qwebr-editor-toolbar-right-buttons';
// Create Run Code button
var runCodeButton = document.createElement('button');
runCodeButton.className = 'btn btn-default qwebr-button qwebr-button-run';
runCodeButton.disabled = true;
runCodeButton.type = 'button';
runCodeButton.id = 'qwebr-button-run-' + qwebrCounter;
runCodeButton.textContent = '🟡 Loading webR...';
runCodeButton.title = `Run code (Shift + Enter)`;
// Append buttons to the leftButtonsDiv
leftButtonsDiv.appendChild(runCodeButton);
// Create Reset button
var resetButton = document.createElement('button');
resetButton.className = 'btn btn-light btn-xs qwebr-button qwebr-button-reset';
resetButton.type = 'button';
resetButton.id = 'qwebr-button-reset-' + qwebrCounter;
resetButton.title = 'Start over';
resetButton.innerHTML = '<i class="fa-solid fa-arrows-rotate"></i>';