Pet*_*ete 5 python web-applications python-3.x bokeh amazon-elastic-beanstalk
我是一名 AWS 初学者,对设置一个非常简单的科学 Web 应用程序感兴趣。我已经确定散景服务器是一个很好的平台。在实际编码方面,我的代码不会与“滑块”演示,源代码这里有太大区别。我可以在sliders.py本地成功运行。
我还预置了一个演示 AWS Elastic Beanstalk 应用程序。我使用了“运行 Python 3.4(预配置 - Docker)的 64 位 Debian jessie v2.7.3。我已经docker-python-v1.zip从Elastic Beanstalk 示例成功上传和部署。
我遇到的问题是将两者结合起来 - 在 Elastic Beanstalk 上运行 Bokeh 服务器。不幸的是,我无法阅读 AWS 和 bokeh-server 文档,而且我无法在网上找到其他资源来将两者结合起来。如何从 Elastic Beanstalk 启动散景服务器应用程序?具体来说,您如何构建一个可以在默认 Elastic Beanstalk Python Docker 上上传的.zip 包?
经过大量的尝试和错误后,我终于能够让它工作了。我创建了一个 git 存储库,其中包含入门所需的一切,但这对于生产来说肯定是不够的:
\n\nhttps://github.com/denson/bokeh_beanstalk_helloworld
\n\nDocker 文件:
\n\n# docker build -t standalone_embed .\n# docker image ls\n# docker run -p 80:5006 standalone_embed\n\n# List all containers (only IDs) docker ps -aq.\n# Stop all running containers. docker stop $(docker ps -aq)\n# Remove all containers. docker rm $(docker ps -aq)\n# Remove all images. docker rmi $(docker images -q)\n\n\nFROM continuumio/miniconda3\n\n# Set the ENTRYPOINT to use bash\n# (this is also where you\xe2\x80\x99d set SHELL,\n# if your version of docker supports this)\nENTRYPOINT [ \xe2\x80\x9c/bin/bash\xe2\x80\x9d, \xe2\x80\x9c-c\xe2\x80\x9d ]\n\nEXPOSE 5006\n\nCOPY . /\nWORKDIR /\n\n# Conda supports delegating to pip to install dependencies\n# that aren\xe2\x80\x99t available in anaconda or need to be compiled\n# for other reasons. In our case, we need psycopg compiled\n# with SSL support. These commands install prereqs necessary\n# to build psycopg.\nRUN apt-get update && apt-get install -y \\\n libpq-dev \\\n build-essential \\\n&& rm -rf /var/lib/apt/lists/*\n\n# Install pyviz\n# http://pyviz.org/installation.html\n\n# update conda and install pyviz\nRUN conda update conda\nRUN conda update conda\n# RUN conda install -c pyviz/label/dev pyviz\n\n# install flask and Bokeh\n\nRUN conda install -c conda-forge bokeh\nRUN conda install -c anaconda flask\nRUN conda install -c anaconda pandas\n\n\n\n# We set ENTRYPOINT, so while we still use exec mode, we don\xe2\x80\x99t\n# explicitly call /bin/bash\nENTRYPOINT ["python", "./standalone_embed.py"]\n\n# https://github.com/lukauskas/docker-bokeh\n# https://github.com/bokeh/bokeh/issues/7724\nRun Code Online (Sandbox Code Playgroud)\n\n独立嵌入.py
\n\nfrom bokeh.layouts import column\nfrom bokeh.models import ColumnDataSource, Slider\nfrom bokeh.plotting import figure\nfrom bokeh.server.server import Server\nfrom bokeh.themes import Theme\n\nfrom bokeh.sampledata.sea_surface_temperature import sea_surface_temperature\n\ndef modify_doc(doc):\n df = sea_surface_temperature.copy()\n source = ColumnDataSource(data=df)\n\n plot = figure(x_axis_type=\'datetime\', y_range=(0, 25), y_axis_label=\'Temperature (Celsius)\',\n title="Sea Surface Temperature at 43.18, -70.43")\n plot.line(\'time\', \'temperature\', source=source)\n\n def callback(attr, old, new):\n if new == 0:\n data = df\n else:\n data = df.rolling(\'{0}D\'.format(new)).mean()\n source.data = ColumnDataSource(data=data).data\n\n slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")\n slider.on_change(\'value\', callback)\n\n doc.add_root(column(slider, plot))\n\n doc.theme = Theme(filename="theme.yaml")\n\n# Setting num_procs here means we can\'t touch the IOLoop before now, we must\n# let Server handle that. If you need to explicitly handle IOLoops then you\n# will need to use the lower level BaseServer class.\n# To allow connections only from a trusted domain set allow_websocket_origin to the domain\n# server = Server({\'/\': modify_doc}, num_procs=1, address="0.0.0.0", port=5006, allow_websocket_origin=["flaskhelloworld-env.gktytvudba.us-east-2.elasticbeanstalk.com"])\n# to allow connections from anywhere\nserver = Server({\'/\': modify_doc}, num_procs=1, address="0.0.0.0", port=5006, allow_websocket_origin=["*"])\n\nserver.start()\n\nif __name__ == \'__main__\':\n print(\'Opening Bokeh application on http://0.0.0.0:5006/\')\n\n server.io_loop.add_callback(server.show, "/")\n server.io_loop.start()\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
579 次 |
| 最近记录: |