R 让闪亮的应用程序在计时器倒数为零时做出反应
我已经设置了一个计时器作为反应值。价值$total。它被设计为倒计时到2017-03-22 23:55:40,当值$total倒计时到零时,它应该将tally添加到值$total。然而,当我启动一个应用程序时,$total的值被冻结并且不移动。我怎样才能让它倒计时R 让闪亮的应用程序在计时器倒数为零时做出反应,r,shiny,R,Shiny,我已经设置了一个计时器作为反应值。价值$total。它被设计为倒计时到2017-03-22 23:55:40,当值$total倒计时到零时,它应该将tally添加到值$total。然而,当我启动一个应用程序时,$total的值被冻结并且不移动。我怎样才能让它倒计时 library(shiny) library(lubridate) ui <- fluidPage( "Total:", textOutput("total", inline = TRUE), "Draft Cou
library(shiny)
library(lubridate)
ui <- fluidPage(
"Total:",
textOutput("total", inline = TRUE),
"Draft Count:",
textOutput("draft_count", inline = TRUE),
"Time:",
textOutput("time",inline=TRUE)
)
server <- function(input, output, session) {
values <- reactiveValues(total = as.numeric(as.POSIXct("2017-03-22 23:55:40")-now(),units="secs"))
values2 <- reactiveValues(total = 0)
observeEvent(values$total <= 0,{
values2$total <- values2$total + 1
})
output$total <- renderText({
invalidateLater(1000,session)
values$total
})
output$draft_count <- renderText({
invalidateLater(1000,session)
values2$total
})
output$time <- renderText({
invalidateLater(1000,session)
as.character(as.POSIXct(now()))
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(lubridate)
ui我想这就是你想要的:
server <- function(input, output, session) {
#values <- reactiveValues(total = as.numeric(as.POSIXct("2017-03-22 23:55:40")-now(),units="secs"))
val <- reactive({
invalidateLater(1000,session)
<- as.numeric(as.POSIXct("2017-03-22 23:55:40")-now(),units="secs")
} )
values2 <- reactiveValues(total = 0)
observeEvent(values$total <= 0,{
values2$total <- values2$total + 1
})
output$total <- renderText({
invalidateLater(1000,session)
val()
})
output$draft_count <- renderText({
invalidateLater(1000,session)
values2$total
})
output$time <- renderText({
invalidateLater(1000,session)
as.character(as.POSIXct(now()))
})
}
server我想这就是你想要的:
server <- function(input, output, session) {
#values <- reactiveValues(total = as.numeric(as.POSIXct("2017-03-22 23:55:40")-now(),units="secs"))
val <- reactive({
invalidateLater(1000,session)
<- as.numeric(as.POSIXct("2017-03-22 23:55:40")-now(),units="secs")
} )
values2 <- reactiveValues(total = 0)
observeEvent(values$total <= 0,{
values2$total <- values2$total + 1
})
output$total <- renderText({
invalidateLater(1000,session)
val()
})
output$draft_count <- renderText({
invalidateLater(1000,session)
values2$total
})
output$time <- renderText({
invalidateLater(1000,session)
as.character(as.POSIXct(now()))
})
}
服务器