I have a R shiny application in which I have drop down box defined in ui.R
as lib
whose values are c("X","Y","Z") and also a check box called spcheck
which is defined as
checkboxInput("spcheck","label1",value = FALSE))
Other conditions makes this checkbox available only when input$lib=Z
and checking it would make few things appear.
When users select a different library, say X, I want to make the spcheck
value FALSE
, So I added the following code to server.R
observe({
if (input$lib %in% c("X","Y") )
{cat("uncheck called 1 : ",input$spcheck,'\n')
updateCheckboxInput(session,"spcheck","label1,value = FALSE)
cat("uncheck called 2 : ",input$spcheck,'\n')
}
else return()
})
The text displayed at console is :
uncheck called 1 : TRUE
uncheck called 2 : TRUE
Why is it not making the spcheck value FALSE? May be I'm missing something very trivial, but I couldn't figure it out. Any help??
Because it takes a few milliseconds since you tell shiny to update the input until it actually happens. When you call the update method, shiny has to send a message to JavaScript to change the value of the input, and once that's done, JavaScript sends a message back to R saying that the input has a new value. But the
input
variable does not change instantly when you make the call, it'll only have an updated value next time a reactive statement uses theinput$spcheck
variable