How to use JQuery to trigger a button click that procs observeEvent in Shiny?
<p>Let's say that I have two actionButtons in my app that are left and right arrows. They're used to navigate through multiple data tables and plots and given an id of "left" and "right". What I'd like is to be able to navigate with the arrow keys on my keyboard as well. I thought I'd be able to use JQuery to simply trigger a click event on those buttons, but that doesn't appear to get communicated to Shiny.</p>

<p>So, is there a different way for me to do this? Here's the JQuery I'm currently using:</p>

<pre><code>$(document.ready(function() {
    $("body").keydown(function(e) {
        if (e.which === 37) {
            $("#plot-left").trigger("click");
        } else if (e.which === 39) {
            $("#plot-right").trigger("click");
        }
     });
});
</code></pre>

<p>On Shiny's side, I've got this code:</p>

<pre><code>  increase_counter &lt;- function() {
    values$counter &lt;- values$counter + 1
    if (values$counter &gt; values$cluster_count) values$counter &lt;- 1
  }

  decrease_counter &lt;- function() {
    values$counter &lt;- values$counter - 1
    if (values$counter == 0) values$counter &lt;- values$cluster_count
  }

  observeEvent(input$plot_left, {
    decrease_counter()
  })

  observeEvent(input$plot_right, {
    increase_counter()
  })
</code></pre>

<h2>Edit</h2>

<p>The JQuery function is working, which is proven by the use of <code>console.log()</code> inside of the jquery. The problem is that the triggered button press is not being communicated back to the Shiny server causing it to run its commands.</p>

<p>This isn't a crucial feature, but it'd be nice to accomplish. Thanks!</p>