I write some codes with plotly and Dash in a Jupiter notebook, and then use nbconvert to convert the notebook to a HTML file. Some figures and tables were plotted with plotly only, and some more interactive tables and figures were plotted with Dash.
When I open the html file with any browser (chrome and firefox), it works fine and is able to show all figures.
However, after a while (for how long I don’t know, maybe a few hours), I try to open it again and it is not able to show the figures plotted with Dash, The figures plotted with plotly only (no Dash) were still able to show.
The following are my simplified codes:
from dash import Dash, html, dcc, Input, Output
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly.offline as pyo
import os
from jupyter_dash import JupyterDash
from dash import dash_table
pyo.init_notebook_mode(connected=False)
import plotly.io as pio
pio.renderers.default = "notebook"
file = 'test.csv'
data = pd.read_csv(file)
app = JupyterDash()
app.layout = html.Div(
[
dash_table.DataTable(
id='table-multicol-sorting',
columns=[{"name": i, "id": i} for i in sorted(data.columns)],
data=data.to_dict('records'),
page_size=25,
sort_action='native',
),
]
)
app.scripts.config.serve_locally = True
app.css.config.serve_locally = True
if __name__ == '__main__':
app.run_server(debug=False, port=3456, mode='inline')
When I ran nbconvert, I used the following command (I did install nb_offline_convert)
jupyter nbconvert --to html-offline --OfflineHTMLExporter.mathjax_option=TeX-MML-AM_CHTML,Safe test_dash.ipynb
The table in the HTML file shows after I generate the HTML file, but after a while (probably a few hours or a day) when I open the HTML file again, the table does not show. The error says “127.0.0.1 refused to connect”. It is very weird. It seems it is looking for a server.
So, I did another test. The HTML file was copied to another computer right after it was generated, and it could show the table without any problem.
If I turn off my internet, the table won’t show. After I turn on my internet, the table shows again, after I refresh the browser (I tested within one hour after the HTML was generated).
I also used Dash(), instead of JupyterDash(). It is still the same.
I can not image why it is so. Any help would be greatly appreciated.