在 R Shiny 中触发反应流的键盘快捷键?

Ins*_*nds 2 javascript r reactive-programming shiny

是否可以在 Shiny 应用程序(在 Windows 中)中拥有,说F7Q触发反应流?这个问题提供了使用键盘输入交替选项卡的代码,但我对启动反应流感兴趣。例如,每次用户按下Q键盘时都会“触发”一个按钮。

Nic*_*icE 8

这是基于此答案的示例:

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})
  }
))
Run Code Online (Sandbox Code Playgroud)

您可以使用此页面查找要在 javascript 代码中使用的键码。在本例中,如果按下 q,button则单击具有 id 的元素。