-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
65 lines (54 loc) · 2.37 KB
/
script.js
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
// To be implemented later
document.getElementById('runCode').addEventListener('click', function() {
var datasetId = document.getElementById('dataset-dropdown').value;
var code = document.getElementById('codeInput').value.trim();
var resultContainer = document.getElementById('response-output');
resultContainer.textContent = "Running...";
// Adjust the OpenCPU API endpoint for running R code on datasets
var xhr = new XMLHttpRequest();
xhr.open('GET', `https://play.dhis2.org/40.3.0/api/29/datasets/${datasetId}/runRCode`, true);
xhr.setRequestHeader('Content-Type', 'application/json');
// Pass the R code as a parameter
var params = {
rCode: code
};
xhr.onreadystatechange = function() {
if(xhr.readyState === XMLHttpRequest.DONE) {
var status = xhr.status;
if (status === 0 || (status >= 200 && status < 400)) {
// The request has been completed successfully
resultContainer.textContent = xhr.responseText;
} else {
// Oh no! There has been an error with the request!
resultContainer.textContent = "Error: " + xhr.statusText;
}
}
};
xhr.send(JSON.stringify(params));
});
document.getElementById('runCode').addEventListener('click', function() {
var code = document.getElementById('codeInput').value.trim();
var resultContainer = document.getElementById('response-output');
resultContainer.textContent = "Running...";
// Adjust the OpenCPU API endpoint for running R code
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://cloud.opencpu.org/ocpu/library/stats/R', true); // Adjust the endpoint
xhr.setRequestHeader('Content-Type', 'application/json');
// Pass the R code as a parameter
var params = {
code: code
};
xhr.onreadystatechange = function() {
if(xhr.readyState === XMLHttpRequest.DONE) {
var status = xhr.status;
if (status === 0 || (status >= 200 && status < 400)) {
// The request has been completed successfully
resultContainer.textContent = xhr.responseText;
} else {
// There has been an error with the request!
resultContainer.textContent = "Error: " + xhr.statusText;
}
}
};
xhr.send(JSON.stringify(params));
});