目录

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:

install.packages("keys")

Or install the development version from GitHub with:

# install.packages("devtools")
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:

library(shiny)
library(keys)

hotkeys <- c(
  "1", 
  "command+shift+k", 
  "up up down down left right left right b a enter"
)

ui <- fluidPage(
  useKeys(),
  keysInput("keys", hotkeys)
)

server <- function(input, output, session) {
  observeEvent(input$keys, {
    print(input$keys)
  })
}

shinyApp(ui, server)

You can add binding after application launch using addKeys.

library(shiny)
library(keys)

ui <- fluidPage(
  useKeys(),
  actionButton("add", "Add keybinding")
)

server <- function(input, output, session) {
  observeEvent(input$add, {
    addKeys("keys", c("a", "b", "c"))
  })
  observeEvent(input$keys, {
    print(input$keys)
  })
}

shinyApp(ui, server)

Bindings can be removed after application launch using removeKey.

library(shiny)
library(keys)

ui <- fluidPage(
  useKeys(),
  keysInput("keys", c("a", "b", "c")),
  actionButton("rm", "Remove `a` keybinding")
)

server <- function(input, output, session) {
  observeEvent(input$rm, {
    removeKeys("a")
  })
  observeEvent(input$keys, {
    print(input$keys)
  })
}

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.

关于

提供键、映射与查找相关辅助功能。

325.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号