0

I am using the answer of the following code to create an arbitrary number of action events ushing this code:

Dynamic number of actionButtons tied to unique observeEvent

What I would like to do is now used the observe event to change a reactive value, so this part of the code:

local({
    i <- ii
    observeEvent(eventExpr = input[[paste0("button",i)]],
                 handlerExpr = {print(sprintf("You clicked btn number %d",i))
                 my_reactive() <- i
})
  })

The problem is that i get the following error:

Warning: Error in <-: invalid (NULL) left side of assignment
[No stack trace available]

I presume that its because of the scoping of using local, but cant find a way to either remove the local part.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Jorge Kageyama
  • 393
  • 4
  • 17
  • This statement `my_reactive() <- i` is an issue. You may not be able to modify the reactive object that way. Try `reactiveValues` object. – YBS Feb 16 '21 at 14:31
  • my_reactive is assigned before the for loop, my_reactive<-reactiveVal(), not sure how i would use reactiveValues in this context, or why would it change the behaviour – Jorge Kageyama Feb 16 '21 at 14:34
  • 1
    If it is a `reactiveVal`, you can just state `my_reactive(i)`, instead of `my_reactive() <- i`. – YBS Feb 16 '21 at 14:38
  • it seems that made the trick! thank you! – Jorge Kageyama Feb 16 '21 at 14:40

0 Answers0