I have an R/Shiny app that responds to a selectInput() by doing an expensive operation (fetch data from a DB, compute, produce chart etc).
I would like R to 'cancel' any operations in progress if I choose another element and simply react to the latest choice.
Instead what I see is that it queues up all choices I made and forces me to wait until it executes thru -- for example if i up-arrow thru the combo box.
Here's some sample code -- `
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')
}
}
}