-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
130 lines (97 loc) · 2.94 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# keys <img src="man/figures/logo.png" align="right" height=150/>
<!-- badges: start -->
[![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)
<!-- badges: end -->
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).