我有一个R / Shiny应用程序通过执行昂贵的操作(从数据库获取数据,计算,生成图表等)来响应selectInput()。
如果我选择其他元素并且只是对最新的选择作出反应,我希望R“取消”正在进行的任何操作。
相反,我看到的是,它排除了我所做的所有选择,并迫使我等到它执行通过 - 例如,如果我向上箭头通过组合框。
这是一些示例代码 - “
baseStockData <- reactive({
# Parse out the first part of the ticker descriptor to get the tick
print(input$toolDetrendBase)
print(">>>> in baseStockData")
if (input$stockDetrend)
{
ticker.firstpart <- strsplit(input$toolDetrendBase, " ")[[1]][1]
ticker <- str_replace_all(ticker.firstpart, "[^[:alnum:]]", "")
# parse ticker till first space
print(paste('loading base stock data for', ticker))
db.con <- xdbOpen()
cur.proc.time <- system.time(
stock <- xdbReadStockEvents(db.con,ticker)
)
print(paste('load stock perf :'))
print(cur.proc.time)
xdbClose(db.con)
stock
}
else
{
NA
}
}
)
output$stockViewPanelAdj <-
renderPlot({
print(">>> in stockViewPanelAdj")
stock <- currentStockData()
daterange <- paste(input$stockViewDateStart, '::', input$stockViewDateEnd, sep='')
print(paste('updating view panel for stock data', daterange))
if (input$stockDetrend)
{
print('calculating detrended stock series view')
baseStock <- baseStockData()
calcDetrendStockSeries(stock, baseStock, daterange)
}
else
{
if (input$stockNormalize)
{
baseval <- 100.0 / as.numeric(stock$adj[daterange][1,4])
if (!is.numeric(baseval)) {
baseval <- 1.0
}
print(baseval)
stockvals <- stock$adj[daterange] * baseval
yrange <- c(80,120)
theme <- chartTheme('white')
}
else
{
stockvals <- stock$adj[daterange]
baseval <- 1.0
yrange <- NULL
theme <- chartTheme('black')
}
render.time <- system.time(
chartSeries(stockvals,
name = stock$stock.metadata$Name,
minor.ticks = T,
major.ticks =T,
theme = theme,
yrange = yrange,
TA=c(addBBands())))
print("Render perf")
print(render.time)
if(input$stockNormalize) {
abline(h=100, lwd=2, col='green')
}
}
}