Shiny:inputchanged event and delay of $inputValues


I working on the project - complex Shiny app (many inputs, many conditionalPanels, lots of reactivity).

I would like to get value of 'radioButtons' input (id="test") directly from Shiny.shinyapp.$inputValues['test'] when input changes.

So I binded my code to 'shiny:inputchanged' event:

$(document).on('shiny:inputchanged', function(event){      

and it seems that Shiny.shinyapp.$inputValues is too slow - it stores not updated value of input. I added setTimeout to handle this issue:

$(document).on('shiny:inputchanged', function(event){
  setTimeout(function(){console.log(Shiny.shinyapp.$inputValues['test'])}, 10);


Now it works.

My question - is 10ms timeout setting enough to be sure that $inputValues is always updated (every time in a complex app)? Or maybe there is a better event which is triggered when $inputValues is updated?

Hi there,

The event object has the info you want directly on it: check its name and value properties. In case you're curious, the reason it happens before $inputValues is updated is because it's possible to cancel the update by doing event.preventDefault().

If you really want to do setTimeout, even a value of 0 will probably work.

1 Like

Thank you for your answer and the explanations!

I have to ensure that Shiny.shinyapp.$inputValues is updated, because in the next step (in app), there is a kind of "conditions" system, which works more less like condition in conditionalPanel (having access to input).

I've tried many values for setTimeout - 2 seems to be enough, but just in case I set 10.