Search code examples
rshinyshiny-reactivity

Multiple objects in the same eventReactive


I have a list of reactive objects that i defined with something like this:

myReactiveList <- reactive({

object1 <- some calculation depending on user inputs

object2 <- some calculation depending object 1 and on other user inputs

# put both in reactive list with:
list(
    reactiveObject1 <- reactive({object1}) 
    reactiveObject2 <- reactive({object2}) 
    )
})

Now I would like to add an action button so that the execution only happens once all user inputs have been selected and the user has pressed "Go".

Unfortunately the syntax reactive(input$go , {}) doesn't seem to work. It only works with eventReactive(input$go , {}) which in turn can only work with one object at a time.

What would be the best approach to incorporate input$go in my sequential reactive list?


Solution

  • You can wrap object1 and object2 in a list and call them later using myReactiveList()[[1]] and myReactiveList()[[2]] respectively -

    myReactiveList <- eventReactive(input$go, {
      object1 <- some calculation depending on user inputs
    
      object2 <- some calculation depending object 1 and on other user inputs
    
      # put both in a list
      list(object1, object2)
    })