在报价单内调用输入(quantmod中的TA addline)

时间:2017-09-14 19:30:45

标签: r shiny

您好我在R Shiny的TA包中的chartSeries quantmod选项中调用了输入。

这是代码

library(shiny)
library(quantmod)
ui <- fluidPage(
  plotOutput("chart", click = "SD1")
)

server <- function(input, output){
  df <- reactive(getSymbols("JPM", src = "google", auto.assign = F))
  output$chart <- renderPlot(
    chartSeries(
      df(),
      type = "candlesticks",
      TA = "addLines(v = input$SD1$x, on = 1)"
    )
  )
}

shinyApp(ui, server)

返回object 'input' not found

2 个答案:

答案 0 :(得分:1)

首先提取点击x <- input$SD1$x,然后点击paste0 addLine命令。

library(shiny)
library(quantmod)

ui <- fluidPage(
  plotOutput("chart", click = "SD1")
)

server <- function(input, output){
  df <- reactive({getSymbols("JPM", src = "google", auto.assign = F)})
  output$chart <- renderPlot({
    # Extract click
    x <- input$SD1$x
    # Create addline command 
    addLineCmd <- paste0("addLines(v = ", x, ", on = 1)")
    chartSeries(
      df(),
      TA = addLineCmd
    )
  })
}

shinyApp(ui, server)

答案 1 :(得分:1)

出于某种原因,这有效:

{{1}}