I have input generated, _1,_2, etc...but I want to know which event is fired.
It works : Get the event which is fired in Shiny?
It works : Addressing multiple inputs in shiny
But both don't work, .clientdata_output_aFired_hidden
and d
are fired. In my real app other events hidden or linked with reactive values fire also.
And without input$changed
it works , but without knowing which is fired.
ui <- fluidPage(
tags$head(
tags$script(
"$(document).on('shiny:inputchanged', function(event) {
if (event.name != 'changed') {
Shiny.setInputValue('changed', event.name);
}
});"
)
),
numericInput("a_1", "a_1", 0),
textInput("a_2", "a_2"),
textInput("c", "c"),
textInput("d", "d"),
p("changedInputs"), textOutput("changedInputs"),br(),
p("aFired"),textOutput("aFired")
)
server <- function(input, output, session) {
output$changedInputs <- renderText({
paste("Outside observer: Latest input fired:", paste(input$changed, collapse = ", "))
})
observeEvent({
lapply(
(grep(pattern = "a_+[[:digit:]]|c"
, x = names((input)), value = TRUE)),
function(x) (input)[[x]]
)
}, {
req(input$changed)
if (input$changed == "a_1") {
output$aFired <- renderText("Inside observer: input$a_1 was fired")
} else if (input$changed == "a_2") {
output$aFired <- renderText("Inside observer: input$a_2 was fired")
} else {
output$aFired <- renderText((input$changed))
}
}, ignoreInit = TRUE)
}
shinyApp(ui, server)