Hi all,
I see that invaidagteLater runs every millisecond depending on the parameter we pass. In the below code,
`````print(paste("The value of input$n is", input$n))gets printed in the console after 1000 milliseconds. Can we make it to get printed only once. In case if the
input$n```` changes, then print this statement
Example
#Below is the output I am getting
"The value of input$n is 500"
"The value of input$n is 500"
"The value of input$n is 500"
.
.
.
"The value of input$n is 687" # In cas I change input$n to 687
"The value of input$n is 687"
"The value of input$n is 687"
.
.
.
Expected output (Only 2 lines)
"The value of input$n is 500"
"The value of input$n is 687"
#code below
if (interactive()) {
ui <- fluidPage(
sliderInput("n", "Number of observations", 2, 1000, 500),
plotOutput("plot")
)
server <- function(input, output, session) {
observe({
# Re-execute this reactive expression after 1000 milliseconds
invalidateLater(1000, session)
# Do something each time this is invalidated.
# The isolate() makes this observer _not_ get invalidated and re-executed
# when input$n changes.
print(paste("The value of input$n is", input$n))
})
# Generate a new histogram at timed intervals, but not when
# input$n changes.
output$plot <- renderPlot({
# Re-execute this reactive expression after 2000 milliseconds
invalidateLater(2000)
hist(rnorm(isolate(input$n)))
})
}
shinyApp(ui, server)
}