【问题标题】:I am not able to execute dash-plotly file with Twisted Web Server我无法使用 Twisted Web Server 执行 dash-plotly 文件
【发布时间】:2018-07-06 01:29:17
【问题描述】:

老实说,我真的被困在这里了。我和一位同事在过去一天左右一直在研究这个问题,但我们不知道如何让 python 文件与 Twisted Web 一起使用。 Twisted web 是一个带有内置 WSGI 容器的独立服务器,所以我想让 python 文件中的图形在 8080 端口可用

这是我用来运行使用twisted web 的应用程序的命令行。是的,它在命令行上拼写为“twistd web”。

twistd web --wsgi civfdemo.py --port tcp:8080

下面是 civfdemo.py 文件。命令行和 python 文件中的正确语法是什么? 目前,我得到的错误信息如下: 没有这样的 WSGI 应用程序:'civfdemo.py'

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
server = app.server

text_style = dict(color='#444', fontFamily='sans-serif', fontWeight=300)
plotly_fig = [dict(x=[1,2,3], y=[2,4,8])]


app.layout = html.Div(children=[
    html.H1(children='CIVF'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    html.P('Enter a Plotly trace type into the text box,' \
           'such as histogram, bar, or scatter.', style=text_style),

        dcc.Graph(id='plot1', 
                  figure = {          
                          'data' : plotly_fig , 'layout' : {
                        'title' : 'Test Progress'
                    }

                }
            )

])
if __name__ == '__main__':
    app.server.run()

【问题讨论】:

    标签: python wsgi twisted.web plotly-dash


    【解决方案1】:

    解决方案(由 GusG):

    又度过了漫长的一天,我终于在一位同事的帮助下让它工作了,但使用了不同的包。作为 Python 新手,当然还有 Dash,拍拍我自己的肩膀以解决这个问题。我找到了一个更简单的包,叫做 Flask-Twisted,它将 Flask 和 Twisted 集成在一起。然后我不得不从项目中挖掘一个老问题,因为其中一条导入行已被弃用。然后通过许多示例进行排序,我终于能够在网站上使用破折号显示图表/图形。所以我希望这可以帮助其他可能遇到类似问题的人。

    import flask
    from flask_twisted import Twisted
    
    from dash import Dash
    import dash_core_components as dcc
    import dash_html_components as html
    
    server = flask.Flask(__name__)
    app = Dash(__name__, server = server)
    
    .... Dash code related to plots and figures
    
    if __name__ == '__main__':
        twisted = Twisted(server)
        twisted.run(host='0.0.0.0',port=8050, debug=False)
    

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      相关资源
      最近更新 更多