Python/Flask应用程序中的实时/更新绘图图?

Python/Flask应用程序中的实时/更新绘图图?,python,plotly,Python,Plotly,我用Flask(带有JS前端)构建了一个Webapp,现在我想添加图表来显示我的数据 我设法在它上面嵌入了一个图表,但它是静态的,有没有办法使它成为动态的(例如使用随机值,以便我以后可以将自己的数据添加到其中) HTTP本质上是无状态的,所以如果您想要动态的,您必须在前端完成 如果不了解你的前端,我无法给出具体的例子, 但希望这能让你走上正轨: 通过对后端的AJAX调用以固定的时间间隔更新图表数据 使用扩展数据,通过 您看过plotly streaming吗?或者Dash是的,我看了Dash,

我用Flask(带有JS前端)构建了一个Webapp,现在我想添加图表来显示我的数据

我设法在它上面嵌入了一个图表,但它是静态的,有没有办法使它成为动态的(例如使用随机值,以便我以后可以将自己的数据添加到其中)


HTTP本质上是无状态的,所以如果您想要动态的,您必须在前端完成

如果不了解你的前端,我无法给出具体的例子, 但希望这能让你走上正轨:

  • 通过对后端的AJAX调用以固定的时间间隔更新图表数据
  • 使用扩展数据,通过

您看过plotly streaming吗?或者Dash是的,我看了Dash,我可能会用它!谢谢我会调查的!
def index():

    rng = pd.date_range('1/1/2011', periods=7500, freq='H')
    ts = pd.Series(np.random.randn(len(rng)), index=rng)

    graphs = [

        dict(
            data=[
                dict(
                    x= arr,
                    y=[10, 20, 30],
                    type='scatter'
                ),
            ],
            layout=dict(
                title='first graph'
            )
        ) 

    ]

    # Add "ids" to each of the graphs to pass up to the client
    # for templating
    ids = ['graph-{}'.format(i) for i, _ in enumerate(graphs)]

    # Convert the figures to JSON
    # PlotlyJSONEncoder appropriately converts pandas, datetime, etc
    # objects to their JSON equivalents
    graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)

    return render_template('index.html',
                           ids=ids,
                           graphJSON=graphJSON)