项目作者: r4fun

项目描述 :
:keyboard: Keyboard Shortcuts for 'shiny'
高级语言: R
项目地址: git://github.com/r4fun/keys.git
创建时间: 2020-10-03T19:41:21Z
项目社区:https://github.com/r4fun/keys

开源协议:Other

下载


" class="reference-link">keys

R build
status
CRAN
status
CRAN_Download_Badge
Conda
Version

The goal of keys is to add hotkeys to shiny applications using
Mousetrap. With keys, you
can:

  • Assign hotkeys on app load
  • Add and remove hotkeys from server
  • Pause and unpause hotkeys from server
  • Record keys from server

Installation

Install the released version of keys from CRAN:

  1. install.packages("keys")

Or install the development version from GitHub with:

  1. # install.packages("devtools")
  2. devtools::install_github("r4fun/keys")

You can also install keys with conda-forge. More information here:
https://github.com/conda-forge/r-keys-feedstock

Usage

To use keys, start by adding a dependency to it using useKeys().

Then, you can add a keysInput to the UI:

  1. library(shiny)
  2. library(keys)
  3. hotkeys <- c(
  4. "1",
  5. "command+shift+k",
  6. "up up down down left right left right b a enter"
  7. )
  8. ui <- fluidPage(
  9. useKeys(),
  10. keysInput("keys", hotkeys)
  11. )
  12. server <- function(input, output, session) {
  13. observeEvent(input$keys, {
  14. print(input$keys)
  15. })
  16. }
  17. shinyApp(ui, server)

You can add binding after application launch using addKeys.

  1. library(shiny)
  2. library(keys)
  3. ui <- fluidPage(
  4. useKeys(),
  5. actionButton("add", "Add keybinding")
  6. )
  7. server <- function(input, output, session) {
  8. observeEvent(input$add, {
  9. addKeys("keys", c("a", "b", "c"))
  10. })
  11. observeEvent(input$keys, {
  12. print(input$keys)
  13. })
  14. }
  15. shinyApp(ui, server)

Bindings can be removed after application launch using removeKey.

  1. library(shiny)
  2. library(keys)
  3. ui <- fluidPage(
  4. useKeys(),
  5. keysInput("keys", c("a", "b", "c")),
  6. actionButton("rm", "Remove `a` keybinding")
  7. )
  8. server <- function(input, output, session) {
  9. observeEvent(input$rm, {
  10. removeKeys("a")
  11. })
  12. observeEvent(input$keys, {
  13. print(input$keys)
  14. })
  15. }
  16. shinyApp(ui, server)

For more information about what types of hotkeys you can use, please
take a look at the mousetrap github
repository.

Acknowledgements

All credit goes to Craig Campbell who is
the author of Mousetrap.