http://180.153.251.80:16889/sample-apps/queryPortfolio/
http://180.153.251.80:16889/sample-apps/U-Chart/
- # 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(TTR)
- library(quantmod)
- library(DTSR)
- Getk1d <- function(symbol,beginDate="20140101", endDate=Sys.Date()) {
- d <- NULL
- #print(nchar(symbol))
- #need know the input issueCode is DZH style
- if (mode(symbol) == "character" & length(symbol) == 1 & nchar(symbol) == 12) {
- beginDate <- gsub("-","",beginDate)
- endDate <- gsub("-","",endDate)
- field.set <- "Date,OpenPrice,HighPrice,LowPrice,ClosePrice,Volume,Amount"
- rs <- dts.GetKLine("k1d", symbol, beginDate, endDate, field.set)
- if (rs$ErrorCode == 0){
- d <- rs$Data
- d <- data.frame(as.numeric(c(d[,1])), as.numeric(c(d[,2])), as.numeric(c(d[,3])), as.numeric(c(d[,4])), as.numeric(c(d[,5])), as.numeric(c(d[,6])), as.numeric(c(d[,7])))
- colnames(d) <- c("TDate", "Open", "High", "Low", "Close", "Volume", "Amount")
- rownames(d) <- as.Date(as.character(d$TDate),"%Y%m%d")
- d$TDate <- NULL
- }
- }
- return(d)
- }
- shinyServer(function(input, output) {
- #download historical data from web
- #log <- "download CHL Data from yahoo begin..."
- #getSymbols("CHL",src="yahoo",from="2014-02-01",end=Sys.Date())
- #log <- "download CHL Data from yahoo end"
-
- bColor <- NA
- cStyle <- NA
- indiConnCheckedString <- NULL
-
- k<-reactive({
- if (input$issueCode != "" & length(input$issueCode) == 1 & nchar(input$issueCode) == 12) {
- Getk1d(input$issueCode,"2014-02-01",Sys.Date())
- }
- })
-
- uStyleSI_reative <- reactive({
-
- #radioButton
- if (mode(input$colorRdBtn) == "character")
- bColor <- input$colorRdBtn
-
- #choose style
- if (input$uStyleSI != "")
- cStyle <- input$uStyleSI
-
- #add indicator
- #checkboxInput
- if (input$addMACD)
- indiConnCheckedString <- c(indiConnCheckedString,'addMACD()')
- if (input$addADX)
- indiConnCheckedString <- c(indiConnCheckedString,addADX())
-
- if (input$addATR)
- indiConnCheckedString <- c(indiConnCheckedString,addATR())
-
- if (input$addBBands)
- indiConnCheckedString <- c(indiConnCheckedString,addBBands())
-
- if (input$addCCI)
- indiConnCheckedString <- c(indiConnCheckedString,addCCI())
-
- if (input$addCMF)
- indiConnCheckedString <- c(indiConnCheckedString,addCMF())
-
- if (input$addCMO)
- indiConnCheckedString <- c(indiConnCheckedString,addCMO())
-
- if (input$addDEMA)
- indiConnCheckedString <- c(indiConnCheckedString,addDEMA())
-
- if (input$addDPO)
- indiConnCheckedString <- c(indiConnCheckedString,addDPO())
-
- if (input$addEMA)
- indiConnCheckedString <- c(indiConnCheckedString,addEMA())
-
- if (input$addEVWMA)
- indiConnCheckedString <- c(indiConnCheckedString,addEVWMA())
-
- if (input$addRSI)
- indiConnCheckedString <- c(indiConnCheckedString,addRSI())
-
- if (input$addSAR)
- indiConnCheckedString <- c(indiConnCheckedString,addSAR())
-
- if (input$addSMA)
- indiConnCheckedString <- c(indiConnCheckedString,addSMA())
-
- if (input$addSMI)
- indiConnCheckedString <- c(indiConnCheckedString,addSMI())
-
- if (input$addWMA)
- indiConnCheckedString <- c(indiConnCheckedString,addWMA())
-
- if (input$addWPR)
- indiConnCheckedString <- c(indiConnCheckedString,addWPR())
-
- if (input$addZLEMA)
- indiConnCheckedString <- c(indiConnCheckedString,addZLEMA())
-
-
-
- print(indiConnCheckedString)
-
- isOriginalChart <- "0"
- if (is.null(indiConnCheckedString))
- isOriginalChart <- "1"
-
- print(isOriginalChart)
- if (input$issueCode == "" | length(input$issueCode) != 1 | nchar(input$issueCode) != 12)
- return (NULL)
- data<-k()
- if (isOriginalChart == "1") #set default chart
- chartSeries(name=input$issueCode,data,theme=chartTheme(bColor),type=cStyle)
- else
- chartSeries(name=input$issueCode,data,theme=chartTheme(bColor),type=cStyle,TA=indiConnCheckedString)
- #chartSeries(name=input$issueCode,data,theme=chartTheme(bColor),type=cStyle,TA=c(addMACD(),addEMA(),addSAR()))
- #dev.off()
- })
-
-
- output$uchart <- renderPlot({
- uStyleSI_reative()
- })
-
- })
- # This is the user-interface definition of a Shiny web application.
- # You can find out more about building applications with Shiny here:
- #
- # http://www.rstudio.com/shiny/
- #
- library(shiny)
- shinyUI(pageWithSidebar(
-
- # Application title
- headerPanel("U CHART"),
-
- # Sidebar with a slider input for number of observations
- sidebarPanel(
- textInput("issueCode","issueCode","SH600000.stk"),
-
- selectInput("uStyleSI",
- "Please select chart line style",
- c("bars","line","candlesticks","matchsticks")
- ),
-
- radioButtons("colorRdBtn",
- "U can change backcolor depends on what you like!",
- c("white"="white","black"="black")),
-
- helpText("U can add indicators depends on what you need!"),
- checkboxInput("addMACD","MACD",TRUE),
- checkboxInput("addADX","ADX",FALSE),
- checkboxInput("addATR","ATR",FALSE),
- checkboxInput("addBBands","BBands",FALSE),
- checkboxInput("addCCI","CCI",FALSE),
- checkboxInput("addCMF","CMF",FALSE),
- checkboxInput("addCMO","CMO",FALSE),
- checkboxInput("addDEMA","DEMA",FALSE),
- checkboxInput("addDPO","DPO",FALSE),
- checkboxInput("addEMA","EMA",FALSE),
- checkboxInput("addEVWMA","EVWMA",FALSE),
- checkboxInput("addRSI","RSI",FALSE),
- checkboxInput("addSAR","SAR",FALSE),
- checkboxInput("addSMA","SMA",FALSE),
- checkboxInput("addSMI","SMI",FALSE),
- checkboxInput("addWMA","WMA",FALSE),
- checkboxInput("addWPR","WPR",FALSE),
- checkboxInput("addZLEMA","ZLEMA",FALSE)
- ),
-
- # Show a plot of the generated distribution
- mainPanel(
- plotOutput("uchart",height="500px")
- #textOutput("log")
- )
- ))