I am looking for a way to bring focus on selectInput
when the user clicks on key 'q'. Can someone show me how to modify the code below?
Right now, clicking on key q
increments the counter in text
by 1.
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"),
selectInput("inputBox", "Select something", choices = c("A","B","C"), selected = "B"),
textOutput("text")),
server=function(input, output, session) {
output$text <- renderText({input$button})
}
))
CodePudding user response:
Use this script:
tags$script(HTML("$(function(){
$(document).keyup(function(e) {
if(e.which == 81){
var selectized = $('#inputBox').selectize();
selectized[0].selectize.focus();
}
});
})")),