R / Shiny - how can I prevent too many costly queuing operations?

I have an R / Shiny application that responds to selectInput () by performing an expensive operation (retrieving data from a database, calculating, creating a chart, etc.).

I would like R to β€œcancel” any operations performed if I select another element and simply respond to the last choice.

Instead, I see that he queues all the options that I have made, and makes me wait until it is executed - for example, if I use the up arrow through the combo box.

Here is a 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') } } } 
+4
source share

All Articles