Skip to content

Instantly share code, notes, and snippets.

@PaulC91
Created November 30, 2018 15:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PaulC91/bd5035875305dfad504f1a3794233186 to your computer and use it in GitHub Desktop.
Save PaulC91/bd5035875305dfad504f1a3794233186 to your computer and use it in GitHub Desktop.
return key trigger actionButton click in shiny example
library(shiny)
ui <- fluidPage(
tags$head(includeScript("returnClick.js")),
textInput("myText", "", placeholder = "Enter text then hit return", width = "100%"),
actionButton("myButton", "Go!"),
verbatimTextOutput("textOutput")
)
server <- function(input, output, session) {
output$textOutput <- renderText({
input$myButton # take a dependency on the button click
# isolate text input to only re-render when button is clicked
isolate(input$myText)
})
}
shinyApp(ui, server)
$(document).keyup(function(event) {
if ($("#myText").is(":focus") && (event.keyCode == 13)) {
$("#myButton").click();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment