Below is a simple R Shiny app example with textInput and actionButton, after clicking the button it is supposed to set the text value to NULL and print NULL value, however I have observed that after clicking the submit button it still prints the value entered in the textInput. Can anyone please explain why there is this delay in updating the textInput value ?
library(shiny)
ui <- fluidPage(
textInput("text", "Test"),
actionButton("Submit","Submit")
)
server <- function(input, output, session) {
observeEvent(input$Submit,{
updateTextInput(session,"text", value = " ")
print(input$text)
})
}
shinyApp(ui, server)
After running the app if I enter "hello" in the text input, I should get " " on the print console, but it shows the value of input$text , i.e "hello" in the print console. Clearly the assignment of " " is not happening in the sequence it is written in the code.
Please share if anyone can explain this behavior in Shiny app. Thank you for your time and suggestions.