以固定的时间间隔更新图形/图表

Ind*_*yen 18 r shiny googlevis shiny-server

我在Shiny UI中有一个情节.如果我改变任何输入参数并通过反应性图将改变.但让我们考虑以下情况: - Shiny UI绘图中的情节让我们说一个股票的日内价格走势.为此,您查询一些实时数据源.现在如果我创建一个刷新按钮然后如果时间过去我继续点击刷新按钮.随着时间进入实时数据源,新数据到达时,绘图将更新.现在我的问题是我不想一直点击刷新按钮.但我希望运行一个带定时器的循环,以便它会检查一段固定的时间间隔,一旦新数据出现,该绘图将自动更新.某种Google财经图表随着时间的推移不断更新.

所以问题可以简化如下: - 让我们从Shiny本身考虑这个例子: - ui.R

library(shiny)    

shinyUI(pageWithSidebar(    

  headerPanel("Hello Shiny!"),

  sidebarPanel(
    sliderInput("obs", 
                "Number of observations:", 
                min = 1,
                max = 1000, 
                value = 500)
  ),

  mainPanel(
    plotOutput("distPlot")
  )
))
Run Code Online (Sandbox Code Playgroud)

和server.R

library(shiny)

shinyServer(function(input, output) {

  output$distPlot <- renderPlot({

    # generate an rnorm distribution and plot it
    dist <- rnorm(input$obs)
    hist(dist)
  })

})
Run Code Online (Sandbox Code Playgroud)

现在我想从正态分布生成一个不同的随机样本,没有任何输入活动.所以基本上我想打电话

dist <- rnorm(input$obs)
hist(dist)
Run Code Online (Sandbox Code Playgroud)

再次不改变sliderInput.请帮我看看如何做到这一点.

jdh*_*son 23

例如,您可以在本地运行以下命令:

library(shiny)

runApp(list(
  ui = pageWithSidebar(    

  headerPanel("Hello Shiny!"),

  sidebarPanel(
    sliderInput("obs", 
                "Number of observations:", 
                min = 1,
                max = 1000, 
                value = 500)
  ),

  mainPanel(
    plotOutput("distPlot")
  )
),
  server =function(input, output, session) {
    autoInvalidate <- reactiveTimer(5000, session)
    output$distPlot <- renderPlot({
      autoInvalidate()
      # generate an rnorm distribution and plot it
      dist <- rnorm(input$obs)
      hist(dist)
    })

  }
))
Run Code Online (Sandbox Code Playgroud)

每5秒生成一个不同的正常样本