Paul Reiners Paul Reiners - 3 months ago 23
R Question

R Shiny: eventReactive with two controls

I have the following R Shiny code:

economics_points <- eventReactive(input$sigmaThresholdSlider, {
print("input$sigmaThresholdSlider fired.")
get_points(input$daterange, 1, input$sigmaThresholdSlider)
}, ignoreNULL = FALSE)
economics_points <- eventReactive(input$daterange, {
print("input$daterange fired.")
get_points(input$daterange, 1, input$sigmaThresholdSlider)
}, ignoreNULL = FALSE)


The problem is that
economics_points
is only updated when the
daterange
control is changed, not when the
sigmaThresholdSlider
control is changed. If I reverse the order of the two statements,
economics_points
is only updated when
sigmaThresholdSlider
is moved. In other words, the second statement overrides the first.

How do I change this code so that it runs when either control is adjusted?

The documentation says that the
eventExpr
argument of
eventReactive
can be "even a complex expression inside curly braces", but no helpful examples are given.

Answer

I don't think you need eventReactive here - you could just use reactive, and it will respond to either value changing.

economics_points <- reactive(get_points(input$daterange, 1, input$sigmaThresholdSlider))

EDIT: not sure how to handle the ignoreNULL = FALSE bit, though, doesn't seem to be an option with reactive.