简体   繁体   English

R闪亮的反应式编程:观察vs观察事件

[英]R Shiny reactive programming: observe versus observeEvent

I am currently creating a Shiny app in R. I have reached the point where I putting more advanced reactive programming into my code. 我目前正在R中创建一个Shiny应用程序。我已经在代码中加入了更高级的反应式编程。 At this point, I am trying to understand how to use the observe function within the reactive context. 在这一点上,我试图理解如何在反应上下文中使用观察函数。 However, I also encounter another reactive function call observeEvent. 但是,我也遇到另一个反应函数调用observeEvent。 What is the difference between observe and obsereEvent in R Shiny? R Shiny中的observe和obsereEvent有什么区别?

observe will trigger anytime there is a reactive dependency inside it, if it's an input , reactiveValues , reactiveVal and so on. observe将触发任何时候,里面有活性的依赖性,如果它是一个inputreactiveValuesreactiveVal等。 The observeEvent and eventReactive will only trigger upon a change that is within the scope of the trigger. observeEventeventReactive仅在触发范围内的更改时触发。 Therefore, observeEvent is more conservative than the observe . 因此, observeEventobserve更保守。 Moreover, you might have memory leaks if you use observe incorrectly without flushing or rendering the variables inside it. 此外,如果不正确地使用observe而没有刷新或渲染其中的变量,则可能会导致内存泄漏。 Personally I almost always use observeEvent 我个人几乎总是使用observeEvent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM