In Shiny apps for R, how do I delay the firing of a reactive?

二次信任 提交于 2019-11-28 00:41:50

问题


I have a selectizeInput in my Shiny app. It is in multiple-select mode, so the user can specify more than one selection.

However, the reactives that depend on the selectizeInput get fired every time a selection is added. Suppose that the user intends to select A, B and C. Currently, my app will do it expensive computations for the selections A, A, B and A, B, C, when only the last is required.

The best way I can think to solve this is to delay the firing of the selectizeInput by a second or so to give the user a chance to enter all of the selections. Each new selection should set the timer back to 1 second. I know that Shiny provides an invalidateLater command, but this causes the reactive to fire once now and once later.

How can I get the reactive to only fire once later?


回答1:


You should debounce the reactive.

There is an R implementation here: https://gist.github.com/jcheng5/6141ea7066e62cafb31c



来源:https://stackoverflow.com/questions/31161372/in-shiny-apps-for-r-how-do-i-delay-the-firing-of-a-reactive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!