2017-04-21 77 views

回答

0

參見下面的示例:

library(shiny) 
library(shinyjs) 
# Define UI for application that draws a histogram 
ui <- fluidPage(
    useShinyjs(), 
    sidebarLayout(
     sidebarPanel(
     textInput("txt1", "Text: "), 
     textInput("txt2", "Text: ")   
    ), 
     mainPanel() 
    ) 
) 

# Define server logic required to draw a histogram 
server <- function(input, output) { 
observe({ 
    runjs(" 
    var inputs = $(':input').keypress(function(e){ 
    if (e.which == 13) { 
     e.preventDefault(); 
     var nextInput = inputs.get(inputs.index(this) + 1); 
     if (nextInput) { 
     nextInput.focus(); 
     } 
    } 
    }); 
    ") 
}) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 

的JavaScript是從here並且包括在光澤與shinyjs