This repository was archived by the owner on Dec 12, 2023. It is now read-only.
generated from course-files/BBT4206-Lab15of15-ConsumePlumberAPIOutput
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumePlumberAPIOutput.R
More file actions
65 lines (56 loc) · 2.75 KB
/
ConsumePlumberAPIOutput.R
File metadata and controls
65 lines (56 loc) · 2.75 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
# [OPTIONAL] Initialization, Install and load the required packages ----
if (require("languageserver")) {
require("languageserver")
} else {
install.packages("languageserver", dependencies = TRUE,
repos = "https://cloud.r-project.org")
}
if (require("httr")) {
require("httr")
} else {
install.packages("httr", dependencies = TRUE,
repos = "https://cloud.r-project.org")
}
if (require("jsonlite")) {
require("jsonlite")
} else {
install.packages("jsonlite", dependencies = TRUE,
repos = "https://cloud.r-project.org")
}
# Generate the URL required to access the symptoms-based API ----
base_url_symptoms <- "http://127.0.0.1:5022/symptoms"
params_symptoms <- list(Symptom_1 = "symptom1_value",
Symptom_2 = "symptom2_value",
Symptom_3 = "symptom3_value",
Symptom_4 = "symptom4_value",
Symptom_5 = "symptom5_value",
Symptom_6 = "symptom6_value",
Symptom_7 = "symptom7_value",
Symptom_8 = "symptom8_value")
query_url_symptoms <- httr::modify_url(url = base_url_symptoms, query = params_symptoms)
print(query_url_symptoms)
# Make the request for the symptoms-based prediction through the API ----
model_prediction_symptoms <- GET(query_url_symptoms)
content(model_prediction_symptoms)
content(model_prediction_symptoms)[[1]]
# Parse the response into the right format ----
model_prediction_raw_symptoms <- content(model_prediction_symptoms, as = "text",
encoding = "utf-8")
jsonlite::fromJSON(model_prediction_raw_symptoms)
# Enclose everything in a function ----
get_symptoms_predictions <- function(Symptom_1, Symptom_2, Symptom_3, Symptom_4,
Symptom_5, Symptom_6, Symptom_7, Symptom_8) {
base_url_symptoms <- "http://127.0.0.1:5022/symptoms"
params_symptoms <- list(Symptom_1 = Symptom_1, Symptom_2 = Symptom_2,
Symptom_3 = Symptom_3, Symptom_4 = Symptom_4,
Symptom_5 = Symptom_5, Symptom_6 = Symptom_6,
Symptom_7 = Symptom_7, Symptom_8 = Symptom_8)
query_url_symptoms <- modify_url(url = base_url_symptoms, query = params_symptoms)
model_prediction_symptoms <- GET(query_url_symptoms)
model_prediction_raw_symptoms <- content(model_prediction_symptoms, as = "text", encoding = "utf-8")
jsonlite::fromJSON(model_prediction_raw_symptoms)
}
# Model prediction based on symptoms parameters
get_symptoms_predictions("symptom1_value", "symptom2_value", "symptom3_value",
"symptom4_value", "symptom5_value", "symptom6_value",
"symptom7_value", "symptom8_value")