Run an R Function
/api/r-scripts/v1/do-eval/{scriptName}
Request
- application/json
-
scriptName(required): string
The name of the R script
object
-
asyncFlag:
boolean
Whether to execute the job asynchronously.
-
envName:
string
Name of the conda environment.
-
graphicsFlag:
boolean
Whether to capture images rendered in the script to the result.
-
parameters:
string
A JSON str of (name - value) pairs specifying keyword arguments to be passed into the script.
-
service:
string
Allowed Values:
[ "LOW", "MEDIUM", "HIGH" ]
LEVEL of the service. Default is LOW. -
timeout:
integer(int32)
Minimum Value:
1800
Maximum Value:43200
The timeout limit (in seconds, default 1800s) of asynchronous job. Must be used together with `asyncFlag`=true.
{"parameters":"{\"ds_name\":\"ds_rdata\"}", "asyncFlag":true, "graphicsFlag":true}
Response
- application/json
200 Response
201 Response
400 Response
500 Response
Examples
Example 1
The following example runs the script named RandomRedDots
. The
graphicsFlag
parameter is set to
true
to return the PNG image and
the data from the function in JSON format.
curl -i -X POST --header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' --header 'Accept: application/json' \
-d '{"graphicsFlag":true, "service":"LOW"}' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v1/do-eval/RandomRedDots"
Response Headers
The response headers are the following:
HTTP/1.1 200 OK
Date: Thu, 28 Jul 2022 21:04:18 GMT
Content-Type: application/json
Content-Length: 1820
Connection: keep-alive
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1;mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Content-Security-Policy: frame-ancestors 'none'
Response Body
The result of the REST endpoint is a JSON representation of the value returned from the R script, which includes the image and the data. Image bytes are returned in PNG format. A portion of the returned value is:
{"result":[{"IMAGE":"iVBORw0KGgoAAAANSUhEUg......Fug8AAAAASUVORK5CYII=","DATA":[{
"val":0.01,"id":1},{"val":0.02,"id":2},{"val":0.03,"id":3},{"val":0.04,"id":4
},{"val":0.05,"id":5},{"val":0.06,"id":6},{"val":0.07,"id":7},{"val":0.08,"id
":8},{"val":0.09,"id":9},{"val":0.1,"id":10}],"ID":1}]}
Example 2
The following example runs the script named
test_ggplot2_noinp
. The
graphicsFlag
parameter is set to
true
to return the PNG image and
the data from the function in JSON format.
curl -i -k -X POST --header "Authorization: Bearer ${token}" --header
'Content-Type: application/json' --header 'Accept: application/json' -d
'{"envName": "myrenv", "graphicsFlag": true}'
"<oml-cloud-service-locationurl>/oml/api/r-scripts/v1/do-eval/test_ggplot2_noinp"
Response Body
The result of the REST endpoint is a JSON representation of the value returned from the R script, which includes the image and the data. Image bytes are returned in PNG format.
{
"result": [
{
"IMAGE": "iVBORw0KGgoAAAANSUhE......AAAABJRU5ErkJggg==",
"DATA": "\"hello world\"",
"ID": 1
}
]
}