Skip to content

Instantly share code, notes, and snippets.

@virtualstaticvoid
Last active September 1, 2022 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virtualstaticvoid/b65ffd073d444c398edb42aae4884bd4 to your computer and use it in GitHub Desktop.
Save virtualstaticvoid/b65ffd073d444c398edb42aae4884bd4 to your computer and use it in GitHub Desktop.
Using `XGBoost` on Heroku

Using XGBoost on Heroku

Replication project for #26 xgboost not installing issue on GitHub, for using the XGBoost package in R on Heroku.

Using Heroku's container stack, together with the heroku-docker-r image.

Usage

  • Build

    make build
    
  • Test

    make run
    
  • Deploy

    heroku create --stack=container
    git push heroku main
    

Credits

Sample code from XGBoost documentation.

License

MIT License. Copyright (c) 2022 Chris Stefano. See LICENSE for details.

#
# Example R program
#
# https://xgboost.readthedocs.io/en/stable/R-package/xgboostPresentation.html
require(xgboost)
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')
train <- agaricus.train
test <- agaricus.test
str(train)
dim(train$data)
dim(test$data)
class(train$data)[1]
class(train$label)
FROM virtualstaticvoid/heroku-docker-r:build
CMD ["/usr/bin/R", "--no-save", "-f", "/app/app.R"]
build:
docker:
app: Dockerfile
# install additional packages, using helper function
helpers.installPackages("xgboost")
The MIT License (MIT)
Copyright (c) 2022 Chris Stefano <virtualstaticvoid@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
.PHONY: all build run
# default build target
all::
all:: build
APP ?= $(shell basename $(PWD))
build:
docker build --tag heroku-docker-r-example:$(APP) .
run:
docker run -it --rm heroku-docker-r-example:$(APP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment