skip to Main Content

After converting a Plotly graph to an HTML Page by this code:

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)

How can I store this HTML Page on an S3 bucket?

I tried this code:

fig.write_html('testPage.html', auto_play=False)

But I’m getting this error:

 Read-only file system: 'testPage.html'

2

Answers


  1. To get the latest code examples of all AWS SDKs, including Python, look at the new AWS Code Library here:

    https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html

    You will find hundreds of code examples in many different programming languages. Included in this doc is how to perform Amazon S3 operations using the AWS SDK for Python.

    The Code Library is not the old Code Catelog – its the replacement.

    UPDATE

    Your code to upload an object using Python SDK is here:

    https://docs.aws.amazon.com/code-library/latest/ug/python_3_s3_code_examples.html

    See this topic.

    enter image description here

    Login or Signup to reply.
  2. Assuming you are running this into a lambda:

    import boto3
    import plotly
    import plotly.express as px
    
    df = px.data.stocks()
    fig = px.line(df, x='date', y="GOOG")
    
    file_name = 'testPage.html'
    fig.write_html('/tmp/'+file_name, auto_play=False)
    
    s3_client = boto3.client('s3')
    response = s3_client.upload_file('/tmp/'+file_name, 'my-bucket', file_name)
    

    Make sure the lambda has the right permission in place to upload the file into the s3 bucket.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search