每秒递增并更新绘图的计数器,单位为R
我正在尝试在一个闪亮的应用程序中创建一个计时计数器。当它每秒钟递增一次时,它应该用一些新的特性刷新一个绘图,这取决于计数器。下面是一个基于“老忠实”应用程序的示例。它不起作用,但它得到的想法。我试图让每秒递增并更新绘图的计数器,单位为R,r,shiny,R,Shiny,我正在尝试在一个闪亮的应用程序中创建一个计时计数器。当它每秒钟递增一次时,它应该用一些新的特性刷新一个绘图,这取决于计数器。下面是一个基于“老忠实”应用程序的示例。它不起作用,但它得到的想法。我试图让reactiveTimer()刷新绘图,并用reactiveValues()记录计数器 服务器.R library(shiny) shinyServer(function(input, output) { refreshPlot <- reactiveTimer(intervalMs
reactiveTimer()
刷新绘图,并用reactiveValues()记录计数器
服务器.R
library(shiny)
shinyServer(function(input, output) {
refreshPlot <- reactiveTimer(intervalMs = 1000)
vals <- reactiveValues(counter = 0)
output$distPlot <- renderPlot({
refreshPlot()
vals$counter <- isolate(vals$counter) + 1
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
n_bins <- input$bins + vals$counter
bins <- seq(min(x), max(x), length.out = n_bins)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
invalidaterater
是我要找的。谢谢,迪特。下面是服务器.R的工作原理
library(shiny)
shinyServer(function(input, output, session) {
vals <- reactiveValues(counter = 0)
output$distPlot <- renderPlot({
invalidateLater(millis = 1000, session)
vals$counter <- isolate(vals$counter) + 1
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
n_bins <- input$bins + vals$counter
bins <- seq(min(x), max(x), length.out = n_bins)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
库(闪亮)
shinyServer(功能(输入、输出、会话){
VALinvalidateLater
是我要找的。谢谢,迪特尔。下面是服务器。R
library(shiny)
shinyServer(function(input, output, session) {
vals <- reactiveValues(counter = 0)
output$distPlot <- renderPlot({
invalidateLater(millis = 1000, session)
vals$counter <- isolate(vals$counter) + 1
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
n_bins <- input$bins + vals$counter
bins <- seq(min(x), max(x), length.out = n_bins)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
库(闪亮)
shinyServer(功能(输入、输出、会话){
VAL我手边没有计算机来测试这个,但是看看invalidaterater
我手边没有计算机来测试这个,但是看看invalidaterater