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

编程入门 行业动态 更新时间:2024-10-27 06:28:26
本文介绍了以固定的时间间隔更新图/图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Shiny UI中有一个图.如果我更改任何输入参数,并且通过反应性图将发生变化.但是,让我们考虑以下情况: Shiny UI绘图中的绘图可以说股票的日内价格变动.为此,您查询一些实时数据源.现在,如果我创建一个刷新按钮,然后如果时间流逝,我继续单击刷新按钮.随着时间的流逝,该实时数据源中的新数据将随着新数据的到来而更新. 现在我的问题是我不想一直点击刷新按钮.但是我想使用计时器运行一个循环,以便它将在固定的时间间隔内进行检查,并且一旦有新数据出现,绘图将自动更新.某种Google Finance Graphs,会随着时间的推移而不断更新.

I have a plot in Shiny UI. If I change any input parameter and through reactivity plot will change. But let's consider following situation:- The plot in Shiny UI plotting let say intra-day price move of a stock. And for that you query some live data source. Now If I create a refresh button and then if time passes by I keep on clicking on refresh button. The plot will be updated as new data arrives as time goes into that live data source. Now my question is I don't want to keep clicking on refresh button. But I want to run a loop with timer so that it will check over a fixed interval of time and as soon as new data comes the plot will auto update. Something sort of Google Finance Graphs which keeps updating over time.

因此,可以将问题简化如下:- 让我们从Shiny本身来看这个例子: ui.R

So the problem can be simplified as follows :- Let's consider this example from Shiny itself :- ui.R

library(shiny) shinyUI(pageWithSidebar( headerPanel("Hello Shiny!"), sidebarPanel( sliderInput("obs", "Number of observations:", min = 1, max = 1000, value = 500) ), mainPanel( plotOutput("distPlot") ) ))

和服务器.R

library(shiny) shinyServer(function(input, output) { output$distPlot <- renderPlot({ # generate an rnorm distribution and plot it dist <- rnorm(input$obs) hist(dist) }) })

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

Now I want to generate a different random sample from normal distribution without any input activity. So basically I want to call

dist <- rnorm(input$obs) hist(dist)

再次

而不更改sliderInput. 请帮助我找出方法.

again without changing sliderInput. Please help me find out how to do that.

推荐答案

作为示例,您可以在本地运行以下命令:

As an example you can run the following locally:

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) }) } ))

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

A different normal sample will be generated every 5 seconds

更多推荐

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

本文发布于:2023-10-16 11:27:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间隔   新图   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!