So I have a graph with some click data that has the location of video files in an S3 bucket. The idea is that when the user clicks on a point on the graph it will display a video related to that point, however, the app just seems to refresh.
This was previoyuly working fine when I was storing the downloaded videos in a static folder, however, the videos no longer seem to play at all when stored there
Does anyone have any idea why this might be happening? Or have a solution.
Cheers
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=Tru