Home > database >  How to expose Jupyter cells based on R language as REST API via Jupyter Kernel Gateway?
How to expose Jupyter cells based on R language as REST API via Jupyter Kernel Gateway?

Time:06-09

In Jupyter notebook I created a R cell that has the R following code:

#GET /r/test

data <- read.csv("/home/jovyan/work/data/heart-failure.csv")

# Split the data into training and test sets. (0.75, 0.25) split.
sampled <- sample(1:nrow(data), 0.75 * nrow(data))
train <- data[sampled, ]
test <- data[-sampled, ]
print(train,quote = TRUE, row.names = FALSE)

In order to expose the cell as REST API, I have annotated the cell with the Jupyter Kernel Gateway annotation

#GET /r/test

When I started a docker container that enables the usage of Jupyter Kernel Gateway, I got the error

RuntimeError: No endpoints were discovered. Check your notebook to make sure your cells are annotated correctly.

Does Jupyter Kernel Gateway support R language based cells to be exposed as REST API? If yes, how can I achieve this functionality?

CodePudding user response:

According to the documentation, there is always a space between # and GET, so you need to write # GET /r/test instead:

# GET /r/test

data <- read.csv("/home/jovyan/work/data/heart-failure.csv")

# Split the data into training and test sets. (0.75, 0.25) split.
sampled <- sample(1:nrow(data), 0.75 * nrow(data))
train <- data[sampled, ]
test <- data[-sampled, ]
print(train,quote = TRUE, row.names = FALSE)

  • Related