The following minimal example demonstrates a problem with updating nested outputs followed by updating the inputs with the content they had before the update of the outputs. This minimal example comes from a much larger project, so solutions to the problem like "don't nest the outputs" aren't viable unless Shiny doesn't actually allow nested outputs.
When you run the example, you'll see two radio buttons and a text input. Enter some text and change the radio button. You will see that after the radio button event is handled, the text input has indeed been updated. But if you change the radio button a second time, the text input at the observeEvent() will be blank.
It's like the updateTextInput() function works fine for updating what you see in the browser, but not at all for what Shiny gets back from the browser for that input on the next event.
To add a bit of strange, also note that if you change the updated text input in any way (e.g., add or remove one character to/from it), then it works as expected. Is the problem here my code, my expectations, or a bug in Shiny?
ui <- fluidPage(fluidRow(column(12, tagList(
uiOutput("outer_div")
))))
server <-function(input, output, session) {
updateScreen = function() {
output$outer_div = renderUI(uiOutput("inner_div"))
output$inner_div = renderUI(tagList(
radioButtons(inputId = "button", label="", choices = c("A", "B")),
textInput("text", label="", value="")
))
}
updateScreen() #initialize screen
observeEvent(input$button, {
print(paste0("Text input is ", input$text))
updateTextInput(session, inputId = "text" , value=input$text)
updateRadioButtons(session, inputId="button", selected=input$button)
updateScreen()
})
}
shinyApp(ui = ui, server = server)
insertUIin Shiny 0.14 is a better solution than nested UI. - Xiongbing Jinprint()function cat'ing itself to? Also; calling updateScreen ouside of a reactive and then again in an observer would create a fight no? - Carl BoneriupdateTextInput()replaces what was there and works as far as browser display goes.Print()goes to the RStudio console for debugging. The firstupdateScreen()only runs at startup. - 3D0G