在 Dash 应用程序中更新视频文件会导致整个应用程序刷新

问题描述 投票:0回答:0

所以我有一个图表,其中包含一些点击数据,其中包含视频文件在 S3 存储桶中的位置。这个想法是,当用户点击图表上的一个点时,它会显示与该点相关的视频,但是,应用程序似乎只是刷新。

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import boto3
import dynamo_utils
import plotly_express as px
from datetime import datetime

s3 = boto3.client('s3', aws_access_key_id='', aws_secret_access_key='')

df = dynamo_utils.query_site('data')

# Create a copy dataset so original isn't altered
ddf = df.copy()

dff = df.copy()
dff["Event"] = 1
# If a day, then


# Graph data

app = dash.Dash(__name__)

app.layout = html.Div([

dcc.Graph(
    id='scatter-plot',
    figure=px.scatter(dff, x=dff.Human_Time, y=dff.Event, custom_data=["Machine_Id", "Bucket", "File_Path"]),
     clickData={'points': [{'customdata': ""}]}
 # Set initial click data
),

    html.Div(
    children=html.Video(
        controls=True,
        id='video_player',
        src="",
        autoPlay=True,
        style={'width': "70%", 'text-align': 'center'}
    ),
    className="card",
    style={'text-align': 'center'}
),
])

@app.callback(Output('video_player', 'src'),
          [Input('scatter-plot', 'clickData')])
def updateVideo(clk_data):
# This will cause video data to appear if data in graph if clicked
# No need to display data if there is

    video_file = ""
    if clk_data is None:
        video_src = None
    else:
    # Get the current time for saving files
        now = datetime.now()
        current_time = now.strftime("%H_%M_%S")
        print(clk_data)
    # clk_data allows us to get each
    # machineID = clk_data['points'][0]['customdata'][0]
        bucket = clk_data['points'][0]['customdata'][1].split(" ")[0]
        path = clk_data['points'][0]['customdata'][2]
        filePath = path.split(".")[0]

        print(filePath)
        print(bucket)

        try:

             s3.download_file(bucket, filePath + ".mp4", 'app/assets/' + "vid_" + str(current_time) + ".mp4")

        except:
             print("video not downloading")

        video_file = 'app/assets/'+ "vid_" + str(current_time) + ".mp4"


    return video_file,
if __name__ == '__main__':
    app.run_server(debug=True)

当我将下载的视频存储在静态文件夹中时,这以前工作正常,但是,当存储在那里时,视频似乎根本无法播放。

有人知道为什么会这样吗?或者有解决办法。

python plotly plotly-dash plotly-python
© www.soinside.com 2019 - 2024. All rights reserved.