I am trying to understand why "# Option 1" in server.R doesn't work, but commented "# Option 2" does work. With "# Option 1" being active try typing random string and pressing the button. First time it replaces the values in the textbox with "abc", but all the next times doesn't.
In my understanding val() is already dependent on input$change, so it must re-execute every time the button is pressed, furthermore "# Option 2" is wrapped into isolate(), so it doesn't add any reactivity.
It seems that actually the value partially changes to "abc" when using "# Option 1". Having Google Chrome's inspect element opened you can see that "# Option 2" changes the values of <input id="txt" type="text" ...> every time the button is pressed, "# Option 1" also changes the value to "abc", but the the screen is updated only when the button is pressed for the first time.
Here is the code:
server.R
shinyServer(function(input, output) {
val <- reactive({
if(input$change>0) {
# Option 1
'abc'
# # Option 2
# isolate({
# paste('abc',input$txt,"")
# })
} else {
''
}
})
output$textbox <- renderUI({
textInput("txt","Text",val())
})
})
ui.R
shinyUI(pageWithSidebar(
headerPanel('Test'),
sidebarPanel(
uiOutput("textbox"),
actionButton("change", "Change")
),
mainPanel(
)
))