# devtools::install_github("gregce/ipify")
# install.packages("caret", dependencies = TRUE)
# install.packages("caTools", dependencies = TRUE)
# install.packages("evtree", dependencies = TRUE)
# install.packages("twilio")
# ssh -i "Shiny.pem" ubuntu@ec2-18-222-226-213.us-east-2.compute.amazonaws.com
library(tidyverse)
library(tibble)
library(jsonlite)
library(caret)
library(caTools)
library(ipify)
library(awscar)
library(twilio)
# Meta data
model_name = "yaaaay"
localhost = "50.236.138.35"
current_ip = get_ip()
home = current_ip == localhost
receive = FALSE
if(!home) {
# First you need to set up your accound SID and token as environmental variables
Sys.setenv(TWILIO_SID = "AC30a981ac2a62872cfae61cab6d6425cb")
Sys.setenv(TWILIO_TOKEN = "13e0c879af0aff8b0f4fad93cf3c7209")
# Then we're just going to store the numbers in some variables
my_phone_number <- "2549318313"
twilios_phone_number <- "12548314407"
# Now we can send away!
tw_send_message(from = twilios_phone_number,
to = my_phone_number,
body = model_name)
}
if(home) {
# Do some pre-processing
sampleSplit = sample.split(mtcars$cyl, .7)
train = mtcars[sampleSplit,]
test = mtcars[-sampleSplit,]
write_csv(train, 'train.csv')
write_csv(test, 'test.csv')
}
# Code to run server side.
if(!home) {
get_it(model_name)
train = read_csv('train.csv')
test = read_csv('test.csv')
# Create the model formula
modelForm = formula(cyl ~ .)
model = "ranger"
control <- trainControl(method="repeatedcv", number=5, repeats=3)
fit <- train(modelForm , data=train, method=model, trControl = control)
# pred = predict(fit, test)
saveRDS(fit, paste0(model_name,"_model.rda"))
if(!home) {
# Now we can send away!
tw_send_message(from = twilios_phone_number,
to = my_phone_number,
body = paste0(model_name, " finished processing!"))
}
}
if(receive) {
system(paste0("aws s3 cp ", " s3://awscar/",model_name, "_model.rda ", model_name, "_model.rda"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.