Let\'s say we have a set of widgets each with their own input label. How do we create a reactive object whose value is the character that represents the input ID of the last
Here's a solution that works, though it looks a little awkward because of a nested observe()
. I'm not sure what a better way would be, but there could be something nicer.
Basically, use an observe()
to loop over all the available inputs, and for each input, use another observe()
that will only trigger when that input is changed and set a variable to the id of the input.
runApp(shinyApp(
ui = shinyUI(
fluidPage(
textInput('txt_a', 'Input Text A'),
textInput('txt_b', 'Input Text B'),
uiOutput('txt_c_out'),
verbatimTextOutput("show_last")
)
),
server = function(input, output, session) {
output$txt_c_out <- renderUI({
textInput('txt_c', 'Input Text C')
})
values <- reactiveValues(
lastUpdated = NULL
)
observe({
lapply(names(input), function(x) {
observe({
input[[x]]
values$lastUpdated <- x
})
})
})
output$show_last <- renderPrint({
values$lastUpdated
})
}
))