Hi,
I’m not able to find any documentation about it, I hope these kind of questions are acceptable on the forum, thanks!
Germán
Hi,
I’m not able to find any documentation about it, I hope these kind of questions are acceptable on the forum, thanks!
Germán
Oh, so I figured this, it’s just like flask,
if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0')
Just like Flask, app.run_server
should be used only for development. You need a proper WSGI server for production.
How would you configure Dash to run on a WSGI server? I’m new to Flask I was trying to run a dashboard on pythonanywhere with no luck. I found this thread from their site https://www.pythonanywhere.com/forums/topic/11357/ where someone else was trying to do the same. If anyone has any advice that would be great!
This works for me:
server = Flask(__name__)
app = dash.Dash(name='app1', sharing=True, server=server, csrf_protect=False)
to run:
gunicorn ...flags.. "app:server"
or, in Dockerfile:
EXPOSE 5000
WORKDIR "/src"
CMD gunicorn -w 10 -b 0.0.0.0:5000 -t 100000 --max-requests 20 app:server
I have just deployed a guide to deployment (heroku) here as well: https://plot.ly/dash/deployment. Hope that helps!
That’s great I’ll check it out! Thanks!
I am trying to deploy Dash on Azure Web App Services. I followed the tutorial (thanks for it) but it deviates in the deployment process. Somehow I always receive “You do not have permission to view this directory or page.” after deploying. Any ideas?
Branching this off to a separate discussion here: Deploying Dash on Azure
Not sure if anyone still looking for the solution here but as I spend couple of hours looking for it I have created docker files for both python2 and python3 for dash server with external ip address here. https://github.com/TahaSolutions/dash
I also created a Dash app mounted on a docker that allows it as well.
You can also change the code and just hit refresh to see the change on the app.
Hope it helps
Hi,
I tried your docker. It works with app.py . but if you I use different plotly script. it cannot start. does it only support app.py?
You need to play with this line in docker file.
CMD [“python”, "app.py”]
Here you suppose to tell python which script to run.
Regards
Shahrouz
Hi, Taha,
thanks for your information. currently I run the docker image you created by this way.
docker run -d --mount src=pwd
,target=/world,type=bind -p 8060:8050 dash_image python3 /world/app2.py
I can run the plotly pyton (app.py) located in the host machine. (I used “–mount” parameter.) The problem is that when I changed to another plotly python script, it cannot run.
for example, in this script I used below.
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
from flask import Flask
server = Flask(name)
df = pd.read_csv(
‘https://raw.githubusercontent.com/plotly/’
‘datasets/master/gapminderDataFiveYear.csv’)
#external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
#app = dash.Dash(name, external_stylesheets=external_stylesheets)
app = dash.Dash(name=‘app1’, sharing=True, server=server, csrf_protect=False)
app.layout = html.Div([
dcc.Graph(id=‘graph-with-slider’),
dcc.Slider(
id=‘year-slider’,
min=df[‘year’].min(),
max=df[‘year’].max(),
value=df[‘year’].min(),
marks={str(year): str(year) for year in df[‘year’].unique()}
)
])
@app.callback(
dash.dependencies.Output(‘graph-with-slider’, ‘figure’),
[dash.dependencies.Input(‘year-slider’, ‘value’)])
def update_figure(selected_year):
filtered_df = df[df.year == selected_year]
traces = []
for i in filtered_df.continent.unique():
df_by_continent = filtered_df[filtered_df[‘continent’] == i]
traces.append(go.Scatter(
x=df_by_continent[‘gdpPercap’],
y=df_by_continent[‘lifeExp’],
text=df_by_continent[‘country’],
mode=‘markers’,
opacity=0.7,
marker={
‘size’: 15,
‘line’: {‘width’: 0.5, ‘color’: ‘white’}
},
name=i
))
return {
'data': traces,
'layout': go.Layout(
xaxis={'type': 'log', 'title': 'GDP Per Capita'},
yaxis={'title': 'Life Expectancy', 'range': [20, 90]},
margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
legend={'x': 0, 'y': 1},
hovermode='closest'
)
}
if name == ‘main’:
app.run_server(debug=True, host=‘0.0.0.0’)
the python file is called dash_pandas_gdp_slide.py
It cannot run, even I just use “python3 dash_pandas_gdp_slide.py” .
can you give me some clue?
thanks in advance.
Tony
I’ve solved the problem. I changed the line below
"app = dash.Dash(name=‘app1’, sharing=True, server=server, csrf_protect=False)“ to
app = dash.Dash(name=‘name’, sharing=True, server=server, csrf_protect=False)
and " if name == ‘ main ’:" to
if name == ‘main’:
how to solve this
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://unpkg.com/dash-core-components@0.45.0/dash_core_components/dash_core_components.min.js.map with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
Is your site failing to load, or are you just worried about the warning message? If it’s just blocking a .js.map
file, that shouldn’t be a problem in production.