У меня есть серия textInputs в R Shiny, и я хочу получить и отобразить идентификатор текстового поля с фокусом, то есть того, в котором мигает курсор, в textOutput.
Я пытаюсь сделать это в JavaScript с небольшим успехом.
Это то, с чем я работал:
ui <- fluidPage(
tags$script(' Shiny.setInputValue("focused.element", $(document.activeElement )) '),
textInput(inputId = "text1", label = NULL, value = ""),
textInput(inputId = "text2", label = NULL, value = ""),
textInput(inputId = "text3", label = NULL, value = ""),
textInput(inputId = "text4", label = NULL, value = ""),
textOutput("output1")
)
server <- function(input, output, session) {
output$output1 <- renderText({ input$focused.element })
}
Я хотел бы, чтобы это отображало «текст1», когда курсор находится в первом текстовом вводе, текст2, когда он находится во втором, и т. д.
Прямо сейчас текст из output1 не отображается. Любая помощь будет оценена по достоинству!
Этот ?
library(shiny)
ui <- fluidPage(
tags$script('$(document).ready(function(){ $("input").on("focus", function(e){ Shiny.setInputValue("focusedElement", e.target.id);}); }); '),
textInput(inputId = "text1", label = NULL, value = ""),
textInput(inputId = "text2", label = NULL, value = ""),
textInput(inputId = "text3", label = NULL, value = ""),
textInput(inputId = "text4", label = NULL, value = ""),
textOutput("output1")
)
server <- function(input, output, session) {
output$output1 <- renderText({ input$focusedElement })
}
shinyApp(ui, server)