I need help with using input[["objectOfInterest"]] with observeEvent

I am building an R application that allows the user to create and destroy Tabs at will. Each tab contains several selection box, a plot button, and a couple of plots after the plot button is clicked. The plotting takes a little time, so I don't want to create the plots each time a selection is changed on a tab, but I do want to clear the plots any time a selection on the tab is changed.

If I use observeEvent(input$itemOfInterest1, { }), every thing works correctly. Changing it to observeEvent(input[[paste0("itemOfInterest", tabNumber)]], { }) does not. TabNumber is a global variable and represents the active tab..

Adding to the selectInput code prevents the plots from ever being displayed, because the selectInput is usually called again (for some reason) after the plots are displayed.

Any ideas?

Thanks.

I tested your paste0 logic in an observeEvent function for sendSweetAlert with a fixed global variable and it worked as expected. My guess is that the problem is in your reactivity chain (b/c I'm assuming that tabNumber is being updated), but you may have already known that. It will take more information about your app structure to track why the reactivity isn't producing the expected result.

1 Like

Thank you for your help. I figured out the problem: in observeEvent(input[[paste0("TEST", tabNumber),...) the Global Variable tabNumber is not avalible. If you change tabNumber from a Global Variable to a ReactiveVariable then it works.

rv <- reactiveVariable ( testNumber = 0 )
observeEvent(input[[paste0("TEST",rv$tabNumber,...) works.

1 Like