2

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()

i get this error:

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

1 Answer 1

2

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()

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.