Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Created November 9, 2012 08:02
Show Gist options
  • Save jcheng5/4044364 to your computer and use it in GitHub Desktop.
Save jcheng5/4044364 to your computer and use it in GitHub Desktop.
Reactive time example
shinyServer(function(input, output) {
output$currentTime <- reactiveText(function() {
# Forces invalidation in 1000 milliseconds
invalidateLater(1000)
as.character(Sys.time())
})
randomData <- reactive(function() {
if (!input$pause)
invalidateLater(750)
runif(4)
})
output$random <- reactiveTable(function() {
matrix(randomData(), 2, 2)
})
})
shinyUI(bootstrapPage(
div(class="container",
p(strong("The time is:"),
textOutput("currentTime")
),
p(strong("Here's some random data:"),
tableOutput("random"),
checkboxInput("pause", "Pause updates", FALSE))
)
))
@englianhu
Copy link

englianhu commented Nov 6, 2017

> server <- shinyServer(function(input, output, session) {
+     output$currentTime <- renderText({
+         # Forces invalidation in 1000 milliseconds
+         invalidateLater(1000)
+         
+         as.character(Sys.time())
+     })
+     
+     randomData <- reactive({
+         if (!input$pause)
+             invalidateLater(750)
+         runif(4)
+     })
+     
+     output$random <- renderTable({
+         matrix(randomData(), 2, 2)
+     })
+ })
> ui <- shinyUI(bootstrapPage(
+     div(class="container",
+         p(strong("The time is:"),
+           textOutput("currentTime")
+         ),
+         p(strong("Here's some random data:"),
+           tableOutput("random"),
+           checkboxInput("pause", "Pause updates", FALSE))
+     )
+ ))
> shinyApp(ui, server)

Its cool... ^_^
https://beta.rstudioconnect.com/content/3073/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment