2017-01-16 41 views

回答

2

下面是基於this answer一個例子:

library(shiny) 

runApp(shinyApp(
    ui = fluidPage(
    tags$script(HTML("$(function(){ 
     $(document).keyup(function(e) { 
     if (e.which == 81) { 
     $('#button').click() 
     } 
     }); 
     })")), 
    actionButton("button", "An action button"), 
    textOutput("text")), 
    server=function(input, output, session) { 
    output$text <- renderText({input$button}) 
    } 
)) 

您可以使用this page找到你想要的JavaScript代碼使用的鍵碼。 在此示例中,如果按下q,則會單擊標識爲button的元素。

+0

純金。後續:有沒有辦法檢測「Ctrl + q」?我知道有一些像'e.ctrlKey',但我不知道如何實現它。 –

+1

你可以看看這個[問題](http://stackoverflow.com/questions/10655202/detect-multiple-keys-on-single-keypress-event-in-jquery)。 – NicE