I want to trigger a reactive containing the input id of the last input clicked. What I have works fine for some inputs like numericInput
and textInput
. But it doesn't work for selectInput
or selectizeInput
. I've tried using a variety of selectors in the JS expression, but none are capturing selectInput
or selectizeInput
.
Here's a reprex. When you click on either of the first two inputs, the renderText updates, but it doesn't with the last two.
library(shiny)
ui <- fluidPage(
tags$head(
tags$script(
htmlwidgets::JS("$( document ).on('click', '.form-control, .shiny-bound-input, .selectized', function() {
Shiny.setInputValue('last_input', this.id);
});")
)
),
numericInput("num1", "Numeric", 0),
textInput("text1", "Text"),
selectInput("select1", "Select", choices = LETTERS[1:4]),
selectInput("selectize1", "Selectize", choices = letters[1:4]),
textOutput("textout")
)
server <- function(input, output, session) {
output$textout <- renderText({
input$last_input
})
}
shinyApp(ui, server)