简体   繁体   中英

Deploy Dash with assets folder to AWS Elastic Beanstalk

I was wondering if anyone would be able to advise me on how to upload a Dash app to elastic beanstalk.

I understand from various peoples blogs to ensure that I need:

application = app.server

if __name__ == '__main__':
application.run_server(debug=True,port=8080)

Then I need to freeze the requirements using pip freeze > requirements.txt and zip all the files and upload to AWS Elastic Beanstalk. In all the explanations they have very simple applications with only a single file and that have no "assets" folders containing css files or no connected databases

I was wondering what the process is when you have an assets folder containing various images and css folders of styles etc. I have also connected a RDS database already set up using the URI with sqlalchemy. The app works perfectly when it is on my local machine. I tried zipping every individual file but it has not worked and I am getting quite desperate. I understand that Dash looks for the "assets" folder. Structure found below:

在此处输入图片说明

Thank you very much for your help in advance. If anyone could highlight the exact steps I need to do I would very much appreciate it. I am very new to this.

Regards

I had an identical problem, and here's how I solved it. By default, Dash automatically serves all of the files included in the ./assets folder. Oppositely a webserver on AWS Elastic Beanstalk expects your CSS and other files to be placed in the ./static folder.

You may create a configuration file for AWS Elastic Beanstalk to set configuration options for your static files. I took another approach:

  1. Change your resources' folder name from assets to static .

  2. Update your Python code when you declare Dash app:

     app = dash.Dash(name=__name__, title="My App", assets_folder ="static", assets_url_path="static")
  3. Deploy your app as usual - AWS Elastic Beanstalk will take resources and serve them from the static folder.

My final app has the following structure:

static/
  favicon.ico
  logo.png
  style.css
application.py  # by default, AWS Elastic Beanstalk expects this app name
requirements.txt

References

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM