Hi there,
I'm trying to poll an api for GPS coords every few seconds but I can only get it running constantly upon start-up of the Shiny app. I'd like to allow the user to turn this polling on and off.
Here's a reprex of something similar, the reactive value polls Sys.time() every 1 second, is there a way to get input$button to switch this on and off?
library(shiny)
ui <- fluidPage(actionButton("button", "Start time printing"))
server <- function(input, output) {
valueToPrint <- reactive({
invalidateLater(1000)
valueToPrint <- sprintf("Time is: %s", Sys.time())
})
observeEvent(valueToPrint(), {
print(valueToPrint())
})
}
shinyApp(ui = ui, server = server)
Many thanks!
It's probably me being thick!