-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
I often use observeEvent(x, ...) when I want to tell shiny that a reactive code block should be executed whenever a specific value x changes. Usually observeEvent() does exactly what I want it to do, but because it gets fired when x gets invalidated, then it can also fire when x hasn't changed at all. I realize this is the correct behaviour based on how reactivity works, but in my opinion it's easier for people to think of it as only firing whenever the value changes rather than gets invalidated. So I was wondering if it'd be possible to add a parameter to observeEvent() that will do that?
Example:
library(shiny)
ui <- fluidPage(
actionButton("btn", "Button")
)
server <- function(input, output, session) {
num5 <- reactive({
input$btn
5
})
observeEvent(num5(), {
cat("click\n")
})
}
shinyApp(ui = ui, server = server)
It wouldn't be too far-fetched to think that the observer would only get run when num5() changes. It's wrong, but it can be useful to want to do that.
I realize this may be a strange request that doesn't really fit the reactivity model, and fully accept any incoming judgment if this is a dumb idea