-
-
Notifications
You must be signed in to change notification settings - Fork 388
/
app.R
32 lines (28 loc) · 909 Bytes
/
app.R
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
library(shiny)
jscode <- '
$(function() {
$(document).keypress(function(e) {
if (e.key == "1" || e.key == "2" || e.key == "3") {
Shiny.onInputChange("clickbox", e.key);
}
});
});
'
ui <- fluidPage(
tags$head(tags$script(HTML(jscode))),
h3("Press the keys 1, 2, 3 on your keyboard to tick/untick the boxes"),
checkboxInput("check1", "One"),
checkboxInput("check2", "Two"),
checkboxInput("check3", "Three"),
p("If you noticed that you can't press the same key multiple times in a row,",
a("see the follow-up example",
href = "https://github.com/daattali/advanced-shiny/tree/master/message-javascript-to-r-force"),
"to see how to fix that")
)
server <- function(input, output, session) {
observeEvent(input$clickbox, {
boxname <- paste0("check", input$clickbox)
updateCheckboxInput(session, boxname, value = !input[[boxname]])
})
}
shinyApp(ui, server)