Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每秒递增并更新绘图的计数器,单位为R_R_Shiny - Fatal编程技术网

每秒递增并更新绘图的计数器,单位为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(功能(输入、输出、会话){

VAL
invalidateLater
是我要找的。谢谢,迪特尔。下面是服务器。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