2017-08-31 7 views
2

Shiny Appを作成してchartseriesプロットを表示したいと思います。ただし、addTAプロットは表示されませんでした。Shiny AppのR addTA関数

ui.R::私はその私のコードの下に、オプションに入れたかったので、私はchartseries機能のうち、addTA機能をしたいと思っ

library(shiny) 

shinyUI(fluidPage(
    titlePanel("Stock App"), 

sidebarLayout(
    sidebarPanel(

helpText("HK stock market."), 

textInput("symb", h5("Symbol"), "0005.HK"), 

radioButtons(inputId="period", label=h5("Periodicity"), 
       choices=c("daily","weekly","monthly")), 

radioButtons(inputId="subset", label=h5("Time"), 
       choices=c("last 1 year","last 3 years","last 5 years")), 

checkboxGroupInput("indicator", 
        label = h5("Indicators"), 
        choices = list("addBBands", 
            "Intraday Intensity", 
            "MFI", "Parabolic SAR"), 
        selected = "addBBands") 
    ), 

    mainPanel(
    textOutput("text3"), 
    br(), 
    plotOutput("plot") 
    )))) 

server.R

library(shiny) 
library(quantmod) 


shinyServer(function(input, output) { 

output$text3 <- renderText({ 
    paste("you have chosen a stock ", input$symb) 
}) 

dataInput <- reactive({ 

    getSymbols(input$symb, src = "yahoo", 
      auto.assign = FALSE, periodicity = input$period) 
}) 

    output$plot <- renderPlot({ 
    chartSeries(dataInput(), theme = chartTheme("white"), 
       up.col = "green", dn.col = "red", 
       TA = NULL, name = input$symb, subset = input$subset) 
    addTA(SMA(Cl(na.omit(dataInput())),n=2), col="red", on = 1) 
    addTA(SMA(Cl(na.omit(dataInput())),n=19), col="blue", on = 1) 
}) 
}) 

addTA関数は出力されませんでしたが、何かアドバイスありがとうございます。

答えて

3

あなたquantmodのチャート作成機能は、それらが光沢のあるアプリの中で描かれていることを確認するためにprint(.)で、など、chartSeries/chart_Series, addTA/add_TA, addRSIを呼び出しラップ:

shinyServer(function(input, output) { 

    output$text3 <- renderText({ 
    paste("you have chosen a stock ", input$symb) 
    }) 

    dataInput <- reactive({ 

    getSymbols(input$symb, src = "yahoo", 
       auto.assign = FALSE, periodicity = input$period) 
    }) 

    output$plot <- renderPlot({ 
    print(chartSeries(dataInput(), theme = chartTheme("white"), 
       up.col = "green", dn.col = "red", 
       TA = NULL, name = input$symb, subset = input$subset)) 
    print(addTA(SMA(Cl(na.omit(dataInput())),n=2), col="red", on = 1)) 
    print(addTA(SMA(Cl(na.omit(dataInput())),n=19), col="blue", on = 1)) 
    }) 
}) 
+0

私は1つの以上の質問をすることができますか?これらのインジケータをcheckboxGroupInputに設定すると、クリックしたときにインジケータをどのように表示できますか? addTA関数に入力$インジケータを入れる方法を理解できません。 –

+0

@Peter Chung確かに、いくつかのサンプルコードを書いて、私は見てみましょう(または他の誰かが)。おそらく別の質問でしょうか? – FXQuantTrader

関連する問題