2

Honestly, I am really stuck here. A colleague and I have been working on this for the past day or so and we don't know to get a python file working with Twisted Web. Twisted web is a stand-alone server with a built-in WSGI container, so I want to make the figure from the python file available at port 8080

This is the command line that I am using for running an application using twisted web. And yes, it is spelled 'twistd web' on the command line.

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

And below is the civfdemo.py file. What is the proper syntax in the command line and in the python file to get this working? Presently, the error message the I get is as follows: No such WSGI application: '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()
Nils
  • 2,665
  • 15
  • 30
GusG
  • 363
  • 2
  • 4
  • 11

1 Answers1

1

Solution (by GusG):

After spending another long day I finally got it to work with a help of a colleague, but instead a different package was used. Being new to Python and of course Dash, patting my self on the shoulder for figuring this out. I found a simpler package called Flask-Twisted, which integrates Flask and Twisted together. Then I had to dig up an old question from the project as one of the import lines were deprecated. Then sorting through many examples, I was finally able to display plots/figures using dash on a website. So I hope this may help others who may encounter similar issues.

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)
Nils
  • 2,665
  • 15
  • 30