当前位置: 首页 > 工具软件 > Linux-dash > 使用案例 >

linux部署dash应用

白哲茂
2023-12-01

linux部署dash应用

一、安装gunicorn

pip install gunicorn

二、dash app.py

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_pivottable

from data import data

app = dash.Dash(__name__)
server = app.server
app.title = 'My Dash example'

app.layout = html.Div([
    dash_pivottable.PivotTable(
        id='table',
        data=data,
        cols=['Day of Week'],
        colOrder="key_a_to_z",
        rows=['Party Size'],
        rowOrder="key_a_to_z",
        rendererName="Grouped Column Chart",
        aggregatorName="Average",
        vals=["Total Bill"],
        valueFilter={'Day of Week': {'Thursday': False}}
    ),
    html.Div(
        id='output'
    )
])

@app.callback(Output('output', 'children'),
              [Input('table', 'cols'),
               Input('table', 'rows'),
               Input('table', 'rowOrder'),
               Input('table', 'colOrder'),
               Input('table', 'aggregatorName'),
               Input('table', 'rendererName')])
def display_props(cols, rows, row_order, col_order, aggregator, renderer):
    return [
        html.P(str(cols), id='columns'),
        html.P(str(rows), id='rows'),
        html.P(str(row_order), id='row_order'),
        html.P(str(col_order), id='col_order'),
        html.P(str(aggregator), id='aggregator'),
        html.P(str(renderer), id='renderer'),
    ]


if __name__ == '__main__':
    app.run_server(debug=True)

三、启动gunicorn

(1)配置gunicorn启动,编写XXX.conf文件

workers = 4
threads = 2
bind = '127.0.0.1:8050'
daemon = 'false'
worker_class = 'gevent'
worker_connections = 200
pidfile = '/var/run/gunicorn.pid'

assesslog = '/var/log/gunicorn_access.log'
errorlog = '/var/log/gunicorn_error.log'

loglevel = 'warning'
gunicorn -c xxx.conf app:server

(2) 直接启动

gunicorn -w 4 -b 0.0.0.0:8050 app:server

-w表示进程数量

(3)后台启动

nohup gunicorn -w 4 -b 0.0.0.0:8050 app:server &
 类似资料: