Answer the question
In order to leave comments, you need to log in
Why doesn't the Plotly Dash web application work on the server, but it works on the local machine?
There is a small web application written in Dash Plotly (which combines Flask and React), the application runs on a local machine, runs on a CentOS server, but when you try to open the application from a link in the browser (I tried it in Chrome, Edge), the application ends on the Loading screen .
The code:
from libs.initsetup import InitSetup
import libs.dbops as dbops
import os
import dash
import dash_core_components as dcc
import dash_html_components as html
from flask_caching import Cache
from flask import Flask
on_server = True
if not on_server:
WORKDIR = ""
else:
WORKDIR = "/var/www/mosregwebsite_dash_plot"
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.cs']
server = Flask(__name__)
dash_app = dash.Dash(__name__, external_stylesheets=external_stylesheets, server=server)
dash_app.scripts.config.serve_locally = True
dash_app.css.config.serve_locally = True
cache = Cache(dash_app.server, config={
'CACHE_TYPE': 'filesystem',
'CACHE_DIR': WORKDIR + os.path.join(os.getcwd(), 'cache-directory')
})
TIMEOUT = 1800 # plots are updated every 30 minutes
@cache.memoize(timeout=TIMEOUT)
def return_layout():
clients = InitSetup.read_initfile_json(WORKDIR + os.path.join(os.getcwd(), "jsons", "clients.json"))
HOST, DBUSER, DBPASSWORD, AUTH_PLUGIN, *rest = InitSetup.read_mysql_init_config_file(WORKDIR +
os.path.join(os.getcwd(), "mosregwebsite_dash_plot.config.txt"))
conn, curs = dbops.create_mysql_connection(HOST, DBUSER, DBPASSWORD, AUTH_PLUGIN)
graphs = []
for k, v in clients.items():
x, y = dbops.select_data_for_pictures(curs, k)
graphs.append({'x': x, 'y': y, 'type': 'lineplot', 'name': v})
return html.Div(children=[
dcc.Graph(
style={
'textAlign': 'center',
'height': '900px',
},
id='example-graph',
figure={
'data': graphs,
'layout': {
}
}
)
])
dash_app.layout = return_layout
if __name__ == '__main__':
if not on_server:
dash_app.run_server(host='127.0.0.103', port=8999, debug=False)
else:
HOST, PORT = InitSetup.read_website_settings_from_config_file(
WORKDIR + os.path.join(os.getcwd(), "mosregwebsite_dash_plot.config.txt"))
dash_app.run_server(host=HOST, port=int(PORT), debug=False)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question