绘图自动滚动范围选择器

2024-05-23 21:25:00 发布

您现在位置:Python中文网/ 问答频道 /正文

正在尝试随视频自动滚动范围选择器

任何帮助都将不胜感激。下面是我到目前为止尝试过的一些代码,它只渲染原始绘图的rangeselector,而不自动滚动(即后续绘图)

enter image description here

使用范围选择器制作甘特图

import plotly.figure_factory as ff

def make_timeline(df, current_time=0):
    y = len(df['Task'].unique())
    fig = ff.create_gantt(df, height=y * 15, bar_width=0.2, index_col='Resource', show_colorbar=True, group_tasks=True, title='Tags Timeline')
    fig.update_layout(
        xaxis=dict(
            rangeselector=dict(
            ),
            rangeslider=dict(
                visible=True
            ),
            type="category",
            autorange=False,
            range=(current_time, current_time + 30)
        )
    )
    return fig

主仪表板应用程序

import dash_core_components as dcc

     app.layout = html.Div(

         children=[
             
               dcc.Interval(id="interval-updating-graphs", interval=1000, n_intervals=0),

               html.Div(
                            className="video-outer-container",
                            children=html.Div(
                                className="video-container",
                                children=player.DashPlayer(
                                    id="video-display",
                                    url="https://www.youtube.com/watch?v=9F5FdcVmLOY",#"http://0.0.0.0:8000/PycharmProjects/dash-maf-viz/data/videos/FILE_MAF_20200302T235220Z_SNL-4512-HD.mp4",#"https://www.youtube.com/watch?v=9F5FdcVmLOY",
                                    controls=True,
                                    playing=True,
                                    volume=1,
                                    width="100%",
                                    height="100%",
                                    seekTo=26
                                ),
                            ),
                        ),

                html.Div(
                  id="tags-timeline",
                  className="eight columns",
                  children=[
                     dcc.Graph(id='tags-timeline-graph'),
                   ]
                )
            )

我想这个回调会通过每秒用不同的起点重新绘制图形来自动滚动。(此处未包括:我还尝试每隔30秒调用maketimeline(),以防延迟,但仍然没有重新绘制。)

@app.callback(
    [Output('tags-timeline-graph', 'figure')],
    [Input('video-display', 'currentTime')])
def update_timeline(currentTime):
    if currentTime:
        pass
    else:
        currentTime=0
    return make_timeline(df, currentTime)

Tags: dividtruedftimehtmlvideofig