【问题标题】:Setting up bokeh server on AWS ElasticBeanstalk在 AWS ElasticBeanstalk 上设置散景服务器
【发布时间】:2023-04-02 12:45:01
【问题描述】:

我是一名 AWS 初学者,对设置一个非常简单的科学 Web 应用程序感兴趣。我已经确定bokeh server 是一个很好的平台。在实际编码方面,我的代码不会与"Sliders" demosource code here 相差太大。我可以在本地成功运行sliders.py

我还预置了一个演示 AWS Elastic Beanstalk 应用程序。我使用“运行 Python 3.4(预配置 - Docker)的 64 位 Debian jessie v2.7.3。我已经从 Elastic Beanstalk samples 成功上传并部署了 docker-python-v1.zip

我遇到的困难是将两者结合起来——在 Elastic Beanstalk 上运行 Bokeh 服务器。不幸的是,我正在阅读 AWS 和 bokeh-server 文档,我无法在网上找到其他资源来结合这两者。 如何从 Elastic Beanstalk 启动散景服务器应用程序?具体来说,如何构建一个.zip 准备在默认 Elastic Beanstalk 上上传的包Python 码头工人?

【问题讨论】:

    标签: python python-3.x web-applications bokeh amazon-elastic-beanstalk


    【解决方案1】:

    经过大量的试验和错误,我能够让它工作。我创建了一个 git 存储库,其中包含您入门所需的一切,但它肯定不足以用于生产:

    https://github.com/denson/bokeh_beanstalk_helloworld

    Docker 文件:

    # docker build -t standalone_embed .
    # docker image ls
    # docker run -p 80:5006 standalone_embed
    
    # List all containers (only IDs) docker ps -aq.
    # Stop all running containers. docker stop $(docker ps -aq)
    # Remove all containers. docker rm $(docker ps -aq)
    # Remove all images. docker rmi $(docker images -q)
    
    
    FROM continuumio/miniconda3
    
    # Set the ENTRYPOINT to use bash
    # (this is also where you’d set SHELL,
    # if your version of docker supports this)
    ENTRYPOINT [ “/bin/bash”, “-c” ]
    
    EXPOSE 5006
    
    COPY . /
    WORKDIR /
    
    # Conda supports delegating to pip to install dependencies
    # that aren’t available in anaconda or need to be compiled
    # for other reasons. In our case, we need psycopg compiled
    # with SSL support. These commands install prereqs necessary
    # to build psycopg.
    RUN apt-get update && apt-get install -y \
     libpq-dev \
     build-essential \
    && rm -rf /var/lib/apt/lists/*
    
    # Install pyviz
    # http://pyviz.org/installation.html
    
    # update conda and install pyviz
    RUN conda update conda
    RUN conda update conda
    # RUN conda install -c pyviz/label/dev pyviz
    
    # install flask and Bokeh
    
    RUN conda install -c conda-forge bokeh
    RUN conda install -c anaconda flask
    RUN conda install -c anaconda pandas
    
    
    
    # We set ENTRYPOINT, so while we still use exec mode, we don’t
    # explicitly call /bin/bash
    ENTRYPOINT ["python", "./standalone_embed.py"]
    
    # https://github.com/lukauskas/docker-bokeh
    # https://github.com/bokeh/bokeh/issues/7724
    

    standalone_embed.py

    from bokeh.layouts import column
    from bokeh.models import ColumnDataSource, Slider
    from bokeh.plotting import figure
    from bokeh.server.server import Server
    from bokeh.themes import Theme
    
    from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
    
    def modify_doc(doc):
            df = sea_surface_temperature.copy()
            source = ColumnDataSource(data=df)
    
            plot = figure(x_axis_type='datetime', y_range=(0, 25), y_axis_label='Temperature (Celsius)',
                                        title="Sea Surface Temperature at 43.18, -70.43")
            plot.line('time', 'temperature', source=source)
    
            def callback(attr, old, new):
                    if new == 0:
                            data = df
                    else:
                            data = df.rolling('{0}D'.format(new)).mean()
                    source.data = ColumnDataSource(data=data).data
    
            slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
            slider.on_change('value', callback)
    
            doc.add_root(column(slider, plot))
    
            doc.theme = Theme(filename="theme.yaml")
    
    # Setting num_procs here means we can't touch the IOLoop before now, we must
    # let Server handle that. If you need to explicitly handle IOLoops then you
    # will need to use the lower level BaseServer class.
    # To allow connections only from a trusted domain set allow_websocket_origin to the domain
    # 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"])
    # to allow connections from anywhere
    server = Server({'/': modify_doc}, num_procs=1, address="0.0.0.0", port=5006, allow_websocket_origin=["*"])
    
    server.start()
    
    if __name__ == '__main__':
            print('Opening Bokeh application on http://0.0.0.0:5006/')
    
            server.io_loop.add_callback(server.show, "/")
            server.io_loop.start()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 2017-08-17
      • 2018-03-28
      • 2015-04-26
      • 2014-09-19
      相关资源
      最近更新 更多