2017-08-31 7 views
2

Je voudrais créer une application brillante pour montrer le graphique de la charte graphique. Cependant, il n'a pas montré le complot addTA. Je voudrais faire la fonction addTA de la fonction ChartSeries parce que je voulais les mettre en options, en dessous de son mon code:R addTA fonction dans Shiny App

ui.R:

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) 
}) 
}) 

La fonction addTA n'a pas été générée, aucun conseil, merci.

Répondre

3

Enveloppez vos appels fonction de création de graphiques de quantmod chartSeries/chart_Series, addTA/add_TA, addRSI, etc, avec print(.) pour assurer qu'ils sont tirés dans les applications Shiny:

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

Puis-je poser une autre question? Si je mets ces indicateurs dans le checkboxGroupInput, comment puis-je montrer les indicateurs quand j'ai cliqué? Je ne peux pas comprendre comment mettre l'indicateur d'entrée $ dans la fonction addTA. –

+0

@Peter Chung Bien sûr, donnez un échantillon de code et je vais jeter un oeil (ou quelqu'un d'autre pourrait le faire). Devrait probablement être une autre question si – FXQuantTrader