-
-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathapp.R
37 lines (33 loc) · 762 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
33
34
35
36
37
library(shiny)
jscode <- '
$(function() {
var $els = $("[data-proxy-click]");
$.each(
$els,
function(idx, el) {
var $el = $(el);
var $proxy = $("#" + $el.data("proxyClick"));
$el.keydown(function (e) {
if (e.keyCode == 13) {
$proxy.click();
}
});
}
);
});
'
ui <- fluidPage(
tags$head(tags$script(HTML(jscode))),
actionButton("btn", "Click me to print the value in the text field"),
div("Or press Enter when the text field is focused to \"press\" the button"),
tagAppendAttributes(
textInput("text", NULL, "foo"),
`data-proxy-click` = "btn"
)
)
server <- function(input, output, session) {
observeEvent(input$btn, {
cat(input$text, "\n")
})
}
shinyApp(ui, server)