Yusra Shahid
Yusra Shahid

Reputation: 104

using plumber package in Rscript and running script from cmd

In my Rscript (run.R):

library(plumber)
r <- plumb("script.R")
r$run(host="127.0.0.1",port=8000)

If I run the above code using RStudio or R console it works fine and gives me access after following output:

Starting server to listen on port 8000 Running the swagger UI at http://127.0.0.1:8000/swagger/

but when I try to run the same code as a .R file using Rscript, R CMD BATCH,R < run.R, pm2 it gets stuck at;

Starting server to listen on port 8000

and on accessing address I get 404: Resource Not Found Error. Also, note that I want to run this on windows therefore didn't try littler. Any idea, what I am doing wrong here. Thanks!

Upvotes: 7

Views: 2039

Answers (1)

Jeff Allen
Jeff Allen

Reputation: 17517

run takes a swagger argument that defaults to interactive(). i.e. it only enables swagger if you're running interactively.

You can hardcode this to TRUE if you want Swagger to be enabled on your router even when run programmatically.

r$run(host="127.0.0.1", port=8000, swagger=TRUE)

Upvotes: 7

Related Questions