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.
So, is there a different way for me to do this? Here's the JQuery I'm currently using:
$(document.ready(function() {
$("body").keydown(function(e) {
if (e.which === 37) {
$("#plot-left").trigger("click");
} else if (e.which === 39) {
$("#plot-right").trigger("click");
}
});
});
On Shiny's side, I've got this code:
increase_counter <- function() {
values$counter <- values$counter + 1
if (values$counter > values$cluster_count) values$counter <- 1
}
decrease_counter <- function() {
values$counter <- values$counter - 1
if (values$counter == 0) values$counter <- values$cluster_count
}
observeEvent(input$plot_left, {
decrease_counter()
})
observeEvent(input$plot_right, {
increase_counter()
})
This isn't a crucial feature, but it'd be nice to accomplish. Thanks!