Skip to content

Instantly share code, notes, and snippets.

@BerriJ
Forked from PaulC91/app.R
Created August 28, 2019 08:13
Show Gist options
  • Save BerriJ/97ddbcc441632ab8c214509a87574594 to your computer and use it in GitHub Desktop.
Save BerriJ/97ddbcc441632ab8c214509a87574594 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