R Shiny key entry binding

In a brilliant application, is it possible to have a binding that listens to which key the button is pressed to?

I'm not too familiar with JavaScript, but I'm looking for something like:

window.onkeydown = function (e) { var code = e.keyCode ? e.keyCode : e.which; alert(code); }; 

where then key entry should be used in server.R , for example:

 shinyServer(function(input, output) { output$text <- renderText({ paste('You have pressed the following key:', input$key) }) # ... }) 
+7
r shiny
source share
1 answer

You can add a listener for keystrokes. Shiny.onInputChange can be used to bind a key to a brilliant variable:

 library(shiny) runApp( list(ui = bootstrapPage( verbatimTextOutput("results"), tags$script(' $(document).on("keypress", function (e) { Shiny.onInputChange("mydata", e.which); }); ') ) , server = function(input, output, session) { output$results = renderPrint({ input$mydata }) } )) 

for keydown events you can replace:

  tags$script(' $(document).on("keydown", function (e) { Shiny.onInputChange("mydata", e.which); }); ') 
+18
source share

All Articles