Using enter key with action button in R Shiny

前端 未结 4 1791
挽巷
挽巷 2020-12-08 14:41

I am trying to write a javascript function to extend the R shiny action button demo. I would like the user to be able to enter a number by both clicking the action button an

4条回答
  •  孤街浪徒
    2020-12-08 15:26

    Add below code in shiny app.

    Outside Ui and Server function -

    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();
            }
          });
        }
      );
    });
    '
    

    inside Ui function-

    tags$head(tags$script(HTML(jscode))),
    `data-proxy-click` = "goButton"
    

    goButton - name of actionbutton

    This will work 100% enjoy.

提交回复
热议问题