rfilerdaplumber

Loading a file using R & plumber


I'm trying to use plumber to predict the value of a cost. For the prediction part, I saved my model in a .rda file. Idon't know how to load it in Plumber, Is it possible to load it just like in plane R ? I saw a similar question, but I don't get how to use the functions in Jeff Allen's answer.


Solution

  • Yes, you just load it like in plain R. You can either load it inside your endpoint or you can do it globally. If the data is going to be shared across endpoints, it would be more performant to load it once globally and have all the endpoints share it.

    I've recently put together some docs here: https://book.rplumber.io/runtime that might be of use to you.

    The summary is that something like this should work:

    # Global code; gets executed at plumb() time.
    myData <- load("somedata.Rda")
    
    #' @get /
    function(){
      myData$column # ....
    }