<commit_before>---
layout: article
title: "Mimic Button Press with Enter Key"
excerpt: "Minic a button press with the Enter key"
categories: blog
created: 2018-11-09
comments: false
share: false
ads: false
---

Sometimes it's useful to mimic a button press in a shiny app when the Enter key is pressed, for example when entering a password.  This has been documented before and works well for most situations but fails when the button widget is housed within renderUI.  Here's an alternative that works wherever the password input and button are located.

```R

library(shiny)
library(shinyjs)
library(shinyWidgets)

jscode <- '
  shinyjs.setbutton = function(params) {
    var defaultParams = {
      id: null,
      button: null
    };
    params = shinyjs.getParams(params, defaultParams);
    var el = $("#" + params.id);<commit_msg>add link<commit_after>---
layout: article
title: "Mimic Button Press with Enter Key"
excerpt: "Minic a button press with the Enter key"
categories: blog
created: 2018-11-09
comments: false
share: false
ads: false
---

Sometimes it's useful to mimic a button press in a shiny app when the Enter key is pressed, for example when entering a password.  This has been [documented before](https://github.com/daattali/advanced-shiny/blob/master/proxy-click/app.R) and works well for most situations but fails when the button widget is housed within renderUI.  Here's an alternative that works wherever the password input and button are located.

```R

library(shiny)
library(shinyjs)
library(shinyWidgets)

jscode <- '
  shinyjs.setbutton = function(params) {
    var defaultParams = {
      id: null,
      button: null
    };
    params = shinyjs.getParams(params, defaultParams);
    var el = $("#" + params.id);
{'fraction_non_alphanumeric': 0.08882521489971347, 'fraction_numerical': 0.009169054441260744, 'mean_word_length': 3.9885714285714284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3370018', 'n_tokens_mistral': 521, 'n_tokens_neox': 492, 'n_words': 212}