Quantmod AddLines() Error: Object not found
Quantmod AddLines() Error: Object not found
最近我一直在尝试使用 quantmod 的 addLines() 函数和 Shiny 包在 chartSeries 上叠加技术分析垂直线。但是,当我定义全局变量(本例中为 followThroughDays 和 distributionDays)并将它们用作 addLines 的 "v" 参数的参数时,出现如下错误消息:
未找到对象'followThroughDays'
未找到对象'distributionDays '
followThroughDays <- 2
distributionDays <- 3
output$plot <-
renderPlot({
filtered_data <- window(stock_data, start = graph_start, end = state$progress)
#flags <- getFollowThroughDaysRowNumber(filtered_data)
switch(
input$chartType,
"candle_stick" = chartSeries(filtered_data, TA=list(
"addLines(v=followThroughDays, on=-1, col='grey')",
"addLines(v=distributionDays, on=-1, col='orange')"
)))})
我应该怎么做才能使 addLines 参数可以访问绘制线条的全局变量?当我明确说明存储在变量中的值(例如 2 或 3)时,代码可以工作,但当我直接将变量用作参数时,代码会显示错误消息。
可重现的错误下载:https://drive.google.com/open?id=1ix81cd9gdJG6nXMM1v1WYwBE2nV0loPy
您必须通过使用 paste0
创建 TA
参数值来克服此错误。
library("shiny")
library("ggplot2")
library("shinythemes")
library("lubridate")
library("quantmod")
library("data.table")
#source("dtstore.R")
fetchedStockData <- getSymbols("IBM", auto.assign = FALSE)
ui <-
fluidPage(
plotOutput("plot")
)
followThroughDays <- 300
server <- function(input, output, session) {
TADays <- 3
output$plot <- renderPlot({
chartSeries(fetchedStockData, theme = chartTheme("white"),
type = "line", TA = paste0("addLines(v=",followThroughDays,", on=-1, col='orange')"))
})
}
shinyApp(ui, server)
最近我一直在尝试使用 quantmod 的 addLines() 函数和 Shiny 包在 chartSeries 上叠加技术分析垂直线。但是,当我定义全局变量(本例中为 followThroughDays 和 distributionDays)并将它们用作 addLines 的 "v" 参数的参数时,出现如下错误消息:
未找到对象'followThroughDays'
未找到对象'distributionDays '
followThroughDays <- 2
distributionDays <- 3
output$plot <-
renderPlot({
filtered_data <- window(stock_data, start = graph_start, end = state$progress)
#flags <- getFollowThroughDaysRowNumber(filtered_data)
switch(
input$chartType,
"candle_stick" = chartSeries(filtered_data, TA=list(
"addLines(v=followThroughDays, on=-1, col='grey')",
"addLines(v=distributionDays, on=-1, col='orange')"
)))})
我应该怎么做才能使 addLines 参数可以访问绘制线条的全局变量?当我明确说明存储在变量中的值(例如 2 或 3)时,代码可以工作,但当我直接将变量用作参数时,代码会显示错误消息。
可重现的错误下载:https://drive.google.com/open?id=1ix81cd9gdJG6nXMM1v1WYwBE2nV0loPy
您必须通过使用 paste0
创建 TA
参数值来克服此错误。
library("shiny")
library("ggplot2")
library("shinythemes")
library("lubridate")
library("quantmod")
library("data.table")
#source("dtstore.R")
fetchedStockData <- getSymbols("IBM", auto.assign = FALSE)
ui <-
fluidPage(
plotOutput("plot")
)
followThroughDays <- 300
server <- function(input, output, session) {
TADays <- 3
output$plot <- renderPlot({
chartSeries(fetchedStockData, theme = chartTheme("white"),
type = "line", TA = paste0("addLines(v=",followThroughDays,", on=-1, col='orange')"))
})
}
shinyApp(ui, server)