在IIS上部署Dash破折号 [英] Deploy plotly dash on IIS

查看:104
本文介绍了在IIS上部署Dash破折号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个破折号短划线部署到IIS.
首先,我按照链接中的说明进行操作:
IIS上的烧瓶-James Polera
然后,当我使用此脚本时,它是可行的:

I am trying to deploy a plotly dash to IIS.
First I followed the instructions in the link:
Flask on IIS - James Polera
then when i use this script it is works:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello from FastCGI via IIS!"

if __name__ == "__main__":
    app.run()

但是当我使用此脚本时,它不适用于破折号:

but when i use this script it doesn't works for dash:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[html.H1('Hello Dash!'),
                                html.Div('Dash: Web Dashboard with python'),
                                dcc.Graph(id='example',
                                        figure={'data':[
                                            {'x':[1,2,3],'y':[4,1,3],'type':'bar','name':'SF'},
                                            {'x':[1,2,3],'y':[2,4,5],'type':'bar','name':'NYC'}
                                                        ],
                                                'layout':{'title':'BAR PLOTS'}
                                                })
                                ])

if __name__ == "__main__":
    app.run_server()

我收到此错误:

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "C:\inetpub\wwwroot\mysite\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "C:\inetpub\wwwroot\mysite\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "C:\inetpub\wwwroot\mysite\wfastcgi.py", line 600, in get_wsgi_handler
    handler = __import__(module_name, fromlist=[name_list[0][0]])
  File "C:\inetpub\wwwroot\mysite\app.py", line 1, in <module>
    import dash
  File "C:\ProgramData\Anaconda3\lib\site-packages\dash\__init__.py", line 1, in <module>
    from .dash import Dash, no_update  # noqa: F401
  File "C:\ProgramData\Anaconda3\lib\site-packages\dash\dash.py", line 23, in <module>
    import plotly
  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\__init__.py", line 30, in <module>
    from plotly import (
  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\graph_objs\__init__.py", line 100161, in <module>
    import ipywidgets
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipywidgets\__init__.py", line 23, in <module>
    from IPython import get_ipython
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\terminal\embed.py", line 15, in <module>
    from IPython.core.interactiveshell import DummyMod, InteractiveShell
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 64, in <module>
    from IPython.utils import io
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\io.py", line 94, in <module>
    stdin = IOStream(sys.stdin, fallback=devnull)
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\io.py", line 38, in __init__
    for meth in filter(clone, dir(stream)):
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\io.py", line 37, in clone
    return not hasattr(self, meth) and not meth.startswith('_')
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\io.py", line 81, in closed
    return self.stream.closed
ValueError: underlying buffer has been detached

在我一直在寻找解决方案的两天里,有人可以提供帮助.
谢谢

Someone can help, for two days now that I've been trying to find a solution.
Thanks

推荐答案

您应该公开Flask对象,而不是Dash对象.因此,代码将类似于

You should expose the Flask object, not the Dash object. Hence the code would be something like,

import dash
import dash_core_components as dcc
import dash_html_components as html
from flask import Flask

server = Flask(__name__)  # object to be referenced by WSGI handler
app = dash.Dash(server=server)

app.layout = html.Div(children=[html.H1('Hello Dash!'),
                                html.Div('Dash: Web Dashboard with python'),
                                dcc.Graph(id='example',
                                        figure={'data':[
                                            {'x':[1,2,3],'y':[4,1,3],'type':'bar','name':'SF'},
                                            {'x':[1,2,3],'y':[2,4,5],'type':'bar','name':'NYC'}
                                                        ],
                                                'layout':{'title':'BAR PLOTS'}
                                                })
                                ])

if __name__ == "__main__":
    app.run_server()

请注意,在我的代码示例中,Flask应用程序对象称为 server .因此,按照我的命名约定,应将WSGI_HANDLER值更改为 app.server .

Note that in my code example, the Flask app object is called server. Hence with my naming convention, the WSGI_HANDLER value should be changed to app.server.

这篇关于在IIS上部署Dash破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆