Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r4fun/keys
:keyboard: Keyboard Shortcuts for 'shiny'
https://github.com/r4fun/keys
hacktoberfest hotkeys keyboard-shortcuts mousetrap rstats
Last synced: 3 months ago
JSON representation
:keyboard: Keyboard Shortcuts for 'shiny'
- Host: GitHub
- URL: https://github.com/r4fun/keys
- Owner: r4fun
- License: other
- Created: 2020-10-03T19:41:21.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-16T22:39:35.000Z (almost 3 years ago)
- Last Synced: 2024-05-14T10:31:45.412Z (6 months ago)
- Topics: hacktoberfest, hotkeys, keyboard-shortcuts, mousetrap, rstats
- Language: R
- Homepage: https://r4fun.github.io/keys/
- Size: 269 KB
- Stars: 44
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
- awesome-shiny-extensions - keys - Assign and listen to keyboard shortcuts in Shiny using the Mousetrap JavaScript library. (UI Components / Advanced Interactivity)
- jimsghstars - r4fun/keys - :keyboard: Keyboard Shortcuts for 'shiny' (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# keys
[![R build status](https://github.com/r4fun/keys/workflows/R-CMD-check/badge.svg)](https://github.com/r4fun/keys/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/keys)](https://CRAN.R-project.org/package=keys)
[![CRAN_Download_Badge](https://cranlogs.r-pkg.org/badges/keys)](https://cran.r-project.org/package=keys)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/r-keys.svg)](https://anaconda.org/conda-forge/r-keys)The goal of `keys` is to add hotkeys to shiny applications using [`Mousetrap`](https://github.com/ccampbell/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:
```{r, eval=FALSE}
install.packages("keys")
```Or install the development version from GitHub with:
```r
# 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:
```r
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`.
```r
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`.
```r
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](https://github.com/ccampbell/mousetrap).
## Acknowledgements
All credit goes to [Craig Campbell](https://github.com/ccampbell) who is the author of [`Mousetrap`](https://github.com/ccampbell/mousetrap).