| Title: | Keyboard Shortcuts for 'shiny' |
|---|---|
| Description: | Assign and listen to keyboard shortcuts in 'shiny' using the 'Mousetrap' Javascript library. |
| Authors: | Tyler Littlefield [aut, cre] (Author of Javascript wrapper), Colin Fay [aut] (ORCID: <https://orcid.org/0000-0001-7343-1846>), Craig Campbell [cph] (Author of JavaScript code) |
| Maintainer: | Tyler Littlefield <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.1.1.9000 |
| Built: | 2026-05-18 06:27:16 UTC |
| Source: | https://github.com/r4fun/keys |
Add a key binding from the server side
addKeys(inputId, keys, session = shiny::getDefaultReactiveDomain()) removeKeys(keys, session = shiny::getDefaultReactiveDomain())addKeys(inputId, keys, session = shiny::getDefaultReactiveDomain()) removeKeys(keys, session = shiny::getDefaultReactiveDomain())
inputId |
The input slot that will be used to access the value. |
keys |
A character vector of keys to bind. Examples include, |
session |
The |
Create a key input that can be used to observe keys pressed by the user.
keysInput(inputId, keys, global = FALSE)keysInput(inputId, keys, global = FALSE)
inputId |
The input slot that will be used to access the value. |
keys |
A character vector of keys to bind. Examples include, |
global |
Should keys work anywhere? If TRUE, keys are triggered when inside a textInput. |
## Not run: ui <- fluidPage( keysInput("keys", c( "1", "2", "3", "command+shift+k", "up up down down left right left right b a enter" )), ) server <- function(input, output, session) { observeEvent(input$keys, { print(input$keys) }) } shinyApp(ui, server) ## End(Not run)## Not run: ui <- fluidPage( keysInput("keys", c( "1", "2", "3", "command+shift+k", "up up down down left right left right b a enter" )), ) server <- function(input, output, session) { observeEvent(input$keys, { print(input$keys) }) } shinyApp(ui, server) ## End(Not run)
Create a key input that can be used to record keys pressed by the user.
keysRecordInput(inputId) recordKeys(inputId, session = shiny::getDefaultReactiveDomain())keysRecordInput(inputId) recordKeys(inputId, session = shiny::getDefaultReactiveDomain())
inputId |
The input slot that will be used to access the value. |
session |
The |
if (interactive()) { library(shiny) ui <- fluidPage( useKeys(), keysRecordInput("recorder"), keysInput("keys", "command+shift+k"), actionButton("record", "Record keys") ) server <- function(input, output, session) { observeEvent(input$record, { print("recording keys...") recordKeys("recorder") }) observeEvent(input$recorder, { print("adding keys...") addKeys("keys", input$recorder) }) observeEvent(input$keys, { print(input$keys) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useKeys(), keysRecordInput("recorder"), keysInput("keys", "command+shift+k"), actionButton("record", "Record keys") ) server <- function(input, output, session) { observeEvent(input$record, { print("recording keys...") recordKeys("recorder") }) observeEvent(input$recorder, { print("adding keys...") addKeys("keys", input$recorder) }) observeEvent(input$keys, { print(input$keys) }) } shinyApp(ui, server) }
These functions allow to pause and unpause keyboard watching
pauseKey(session = shiny::getDefaultReactiveDomain()) unpauseKey(session = shiny::getDefaultReactiveDomain())pauseKey(session = shiny::getDefaultReactiveDomain()) unpauseKey(session = shiny::getDefaultReactiveDomain())
session |
The |
if (interactive()){ library(shiny) ui <- fluidPage( useKeys(), keysInput("keys", letters), actionButton("pause", "Pause"), actionButton("unpause", "Unpause") ) server <- function(input, output, session) { observeEvent(input$keys, { print(input$keys) }) observeEvent(input$pause, { pauseKey() }) observeEvent(input$unpause, { unpauseKey() }) } shinyApp(ui, server) }if (interactive()){ library(shiny) ui <- fluidPage( useKeys(), keysInput("keys", letters), actionButton("pause", "Pause"), actionButton("unpause", "Unpause") ) server <- function(input, output, session) { observeEvent(input$keys, { print(input$keys) }) observeEvent(input$pause, { pauseKey() }) observeEvent(input$unpause, { unpauseKey() }) } shinyApp(ui, server) }
This function adds the keys dependencies to your application
useKeys()useKeys()
An html singleton