Extool Platform for R developer (Windows)
Nan Wu
Contents
1.Install R and set environment
1.1 Download and install R
1.2 Set system environment
1.3 Check R version
1.4 Install development IDE
2.Development
3.Test
4.Deploy
5.Run
1.Install R and set environment...... 1
1.1 Download and install R...... 1
1.2 Set system environment...... 1
1.3 Check R version...... 1
1.4 Install development IDE...... 1
2.Development...... 2
3.Test...... 2
4.Deploy...... 3
1.Install R and set environment
1.1 Download and install R
Goto download R installer. Install R on your specified path. With default setup option, R.exe will be under “C:\Program Files\R\R-3.2.3\bin\”.
1.2 Set system environment
On desktop, right-click “Computer” icon, select “Properties”. In opened window, click “Advanced system settings”——>“Environment Variables”. Double-click “path” under “System variables”, add “C:\Program Files\R\R-3.2.3\bin\;” into “Variable value”.
1.3 Check R version
Open cmdline, input “R”, if it shows R version number and other information. You are successfully installed and set up R development environment.
1.4 Install development IDE
You have installed R core, now you should install RStudio to boost your development.
RStudio is an excellent R IDE. You can download it from
2.Development
Extool platform wraps all required data and parameters from Excel cells into a json format file. Based on this file, you can develop your customized app. Generally speaking, to make an app you will handle a local json file includes several online data file links (csv, jpg, and so on) and parameters. The following Stock Chart app example shows how you can do that.
You allow app users provide parameters and data file in Excel cells like below (blue area),
Input ParametersName / Value
rawdata / $K$15:$M$18
width / 1280
height / 720
The value of “rawdata” like follows.
StockSymbol / StartDate / EndDateGOOG / 8/14/2014 / 2/26/2016
AAPL / 10/23/2014 / 2/26/2016
BABA / 1/1/2015 / 2/22/2016
args <- commandArgs(trailingOnly = TRUE)# retrieve parameter cmdline
tempParas<-fromJSON(args[1])# retieve JSON content from parameter
mywidth = tempParas$width# parse width parameter from json
myheight = tempParas$height# parse height parameter from json
stockData = read.csv(tempParas$rawdata, skip = 0)# retrieve csv file path from json then read it into a dataframe
You should care about parameter formats when you begin your development. By default, parameters are passed in “String” format.
The following code shows how to generate a plot.
outputFile = paste("./",stockName,".png",sep = "")# do not specify a output file path
jpeg(file= outputFilepath, width = mywidth, height = myheight,
quality = 75, bg = "white", res = NA )
#……Your plotting code……
dev.off()# make sure to turn off plotting device after plotting each plot.
Please add all code as example here.
Example code as follows,
library(RJSONIO)
library(RCurl)
library(quantmod)
args <- commandArgs(trailingOnly = TRUE)
tempParas<-fromJSON(args[1])
mywidth = as.integer(tempParas[[1]])
stockData = read.csv(tempParas[[2]], skip = 0)
myheight = as.integer(tempParas[[3]])
stocks = as.vector(stockData$StockSymbol)
StartDate = as.Date("1900-01-01") + as.numeric(stockData$StartDate) -2
EndDate = as.Date("1900-01-01") + as.numeric(stockData$EndDate) -2
genPlot<-function(stockName, fromDate, toDate){
outputFile = paste("./",stockName,".png",sep = "")
if(is.null(mywidth)||is.null(myheight)){
jpeg(file= outputFile, width = mywidth, height = myheight,
quality = 75, bg = "white", res = NA )
}else{
jpeg(file= outputFile, width = 1280, height = 720,
quality = 100, bg = "white", res = NA )
}
symb <- getSymbols(stockName, auto.assign = FALSE, from = fromDate, to = toDate)
chartSeries(symb, name = stockName, theme="white",TA="addVo();addBBands();addCCI();addDEMA();addZLEMA()")
dev.off()
}
outputFiles = c()
for(i in 1:length(stocks)){
genPlot(stocks[i], StartDate[i], EndDate[i])
Sys.sleep(0.5)# delay for dev on/off
}
3.Test
As you have seen above, all your needed data and parameters are passed from cmdline parameter. To test your app in local, you should first prepare a valid json file. In previous example, the json file should be like this.
{
"rawdata":"
"width":1280,
"height":720
}
To fill “rawdata” value, you’d better use an online csv file link (i.e. dropbox public link or google drive link), make sure it can be downloaded directly.
Run “RscriptRfilepath\vocano.rjsonfilepath\parameters.json” in cmdline. If your program runs without any error, you will get generated files in current work directory. Basically, if you can get your desired results, the code should work after deploying onto Extool platform.
4.Deploy
There are three steps to deploy your app.1.Create a knowledgebase file 2. Create the app 3. Create the worker.
Before deploying on server, you should prepare your KB sheet first. A knowledgebase is needed to tell end user how to use the app. Create a new excel file and added the following content.
Then use Extool client to create a new app and upload your KB sheet. Note that, you should record your knowledgebase sheet name (i.e. H_R_StockChart) then fill the “Knowledgebase sheets” with it.
To deploy your code on server, you should log in first.
New a folder to store your code file, get its file path.
Then new a folder named as your app name under “C:\apps\”. You should prepare two files in it.
A file named R_StockChartyourappname.batwith content
RscriptC:\ParaTool\ServerRunnable\R\NewStockRRfilepathonserver\RstockNewyourappname.r %1
And a file named info.txtwith content as follows,
name= Multiple Stocks Analysis
After doing all above, the app should be correctly deployed. Open your Extool client, go to search your app name, and try to run it.
5.Run
First you should input “stock” then click “Search” to search your app from library. If it successfully return an apps list, you can double click the app name.
Next, you can download the knowledgebase by clicking “knowledgebase” button.Please
You can run it by first highlighting the parameter range.
add a demo of how to search and run the
A webpage will pop up, you can find three png files (named as ticker’s name) within it.
One of them will like as follows, it decribes the ticker’s price daily (within date frame that provided in knowledgebase sheet) and some inportant technical indexes.
deployed app