用了DTS的数据,基于R 做的一个小例子,得瑟下
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://www.rstudio.com/shiny/
#
library(shiny)
library(DTSR)
Getk1d <- function(symbol,beginDate=Sys.Date()-365, endDate=Sys.Date()) {
d <- NULL
if (mode(symbol) == "character" & length(symbol) == 1) {
beginDate <- gsub("-","",beginDate)
endDate <- gsub("-","",endDate)
field.set <- "Date,ClosePrice"
rs <- dts.GetKLine("k1d", symbol, beginDate, endDate, field.set)
if (rs$ErrorCode == 0){
d <- rs$Data
d <- xts(d$ClosePrice,as.Date(d$Date,"%Y%m%d"),attr=symbol);
}
}
return(d)
}
shinyServer(function(input, output) {
analysis.result<-reactive({
# 获取数据
# y 豆油的数据
# m 豆粕的数据
# a 豆一的数据
y <- Getk1d("DCy0001.cmdty",Sys.Date()-(365 * 3),Sys.Date());
m <- Getk1d("DCm0001.cmdty",Sys.Date()-(365 * 3),Sys.Date());
a <- Getk1d("DCa0001.cmdty",Sys.Date()-(365 * 3),Sys.Date());