[使用从Shiny服务器调用的Quantmod的chartSeries()绘制图表时,技术指标会两次添加到图表中。
如果从控制台执行以下代码,则结果与预期的一样。当由Shiny App服务器执行时,RSI和MACD将两次添加到图表中。尽管打印语句仅显示一次。
getChart.raPortfolio <- function(obj) {
if(is.xts(obj$chart)) {
print("Was here!")
chart <- chartSeries(obj$chart,
name = obj$symbol,
theme = chartTheme("white"),
type = "line", TA=c(
addBBands(n = 50),
addMACD(fast = 12, slow = 26, signal = 9),
addRSI(n=14)
)
)
}
return(chart)
}
该问题是由返回之前分配给图表对象引起的。下面的行为正确。
getChart.raPortfolio <- function(obj) {
chartSeries(obj$data,
name = obj$symbol,
theme = chartTheme("white")
)}