I'm trying to save a graph that was generated by plotly as HTML to S3
I can use this code to generate a html page from Plotly graph and save it locally:
import plotly
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x='date', y="GOOG")
plotly.offline.plot(fig , filename = 'filename.html', auto_open=False)
I tried this code:
bucket.put_object(fig, ContentType='text/html', Key=out_key)
but did not work
CodePudding user response:
Tru to use upload_file()
instead of .put_object()
file_name = 'YourFileName.html'
fig.write_html('/tmp/' file_name, auto_play=False)
s3_client = boto3.client('s3')
response = s3_client.upload_file('/tmp/' file_name,
Writing_Bucket_Name, file_name)