I experience difficulties with Shiny package in R.
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 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
require(shiny)
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
require(shiny)
require(shinyIncubator)
shinyUI(pageWithSidebar(
headerPanel('Test'),
sidebarPanel(
uiOutput("textbox"),
actionButton("change", "Change")
),
mainPanel(
)
))
See my response here:
https://groups.google.com/d/msg/shiny-discuss/PLHauRlFw3k/AnoD7NusvDIJ
The gist is that the server keeps sending exactly the same value to the textbox
output, so the client is "smart" enough to ignore it.
This does look like there might be a bug hidden in there somewhere, but I can't track it down.
The good news is, I think you should be able to accomplish this effect with the updateTextInput
function.
For a deeper look at the issue, I've created a bug for this, however. https://github.com/rstudio/shiny/issues/181 . I'll try to update this post if/when we figure out what's going on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With