forked from daattali/advanced-shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
34 lines (29 loc) · 661 Bytes
/
Copy pathapp.R
File metadata and controls
34 lines (29 loc) · 661 Bytes
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
library(shiny)
jscode <- '
$(function() {
$(document).keypress(function(e) {
Shiny.onInputChange("keypress1", e.key);
Shiny.onInputChange("keypress2:mylist", e.key);
});
});
'
shiny::registerInputHandler("mylist", function(data, ...) {
list(data)
}, force = TRUE)
ui <- fluidPage(
tags$head(tags$script(HTML(jscode))),
h3("Press any key"),
"Raw key press:",
verbatimTextOutput("text1"),
"Key press wrapped in a list:",
verbatimTextOutput("text2")
)
server <- function(input, output, session) {
output$text1 <- renderPrint({
input$keypress1
})
output$text2 <- renderPrint({
input$keypress2
})
}
shinyApp(ui, server)