Navigate inputPicker list with arrow keys

Setting the scene

Dear R community,

im developing a shinydashboard to summarise and display the prescription and diagnosis history of people on a case by case basis (I can disclose no more).

In essence there is a reactive selectInput list of IDs which are updated based on filters the user can set (e.g. group, date range). One can select only one ID at a time and the app displays the records of this ID.

Core Problem

I would like to advance the list of IDs in selectInput to the next/previous ID by using the keyboard (the arrow keys for example). This would save a lot of clicks since quite a few of these IDs and their medication history have to be srcreened.

Potential, but vague, solution

  • A .js script which binds a key to "click" an action button (advance its counter)
    • To modify it I would need to know how I can bind the key to navigate one row down/up the selectInput list.

Thank you very much!

shinyjs has a keypress demo, but be aware that you should contact the author of shinyjs for a commercial license if you have a commercial purpose.

(require(shiny))
(require(shinyjs))
(require(V8))
jscode <- "
shinyjs.init = function() {
  $(document).keypress(function(e) { alert('Key pressed: ' + e.which); });
}"

shinyApp(
  ui = fluidPage(
    useShinyjs(),
    extendShinyjs(text = jscode),
    "Press any key"
  ),
  server = function(input, output) {}
)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.