1 回答

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
任何可用的 Dash 應(yīng)用程序都可以通過JupyterLab啟動(dòng),并使用問題中描述的設(shè)置,方法是use_reloader=False在以下位置指定:
app.run_server(debug=True,
use_reloader=False # Turn off reloader if inside Jupyter
)
但如果您想使用 JupyterLab 并launching the app in your default browser, inline in a cell or directly in Jupyter在其自己的選項(xiàng)卡中進(jìn)行選擇,只需按照以下簡(jiǎn)單步驟操作:
更改以下行
# 1
import dash
# 2
app = dash.Dash()
# 3
app.run_server(debug=True,
use_reloader=False # Turn off reloader if inside Jupyter
)
對(duì)此:
# 1
from jupyter_dash import JupyterDash
# 2
app = JupyterDash(__name__)
# 3
app.run_server(mode='inline', port = 8070, dev_tools_ui=True,
dev_tools_hot_reload =True, threaded=True)
這將直接在 JupyterLab 中內(nèi)聯(lián)啟動(dòng) Dash :
但您也可以mode='external'
啟動(dòng) Dash 它自己的選項(xiàng)卡:
您可以設(shè)置mode='external'在默認(rèn)瀏覽器中啟動(dòng)它。
經(jīng)過更改的完整代碼:'
import plotly.graph_objects as go
import plotly.express as px
# import dash
from jupyter_dash import JupyterDash
import dash_core_components as dcc
import dash_html_components as html
# data and plotly figure
df = px.data.gapminder().query("country=='Canada'")
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
# Set up Dash app
# app = dash.Dash()
app = JupyterDash(__name__)
app.layout = html.Div([
dcc.Graph(figure=fig)
])
# Launch Dash app
# app.run_server(debug=True,
# use_reloader=False # Turn off reloader if inside Jupyter
# )
app.run_server(mode='inline', port = 8070, dev_tools_ui=True,
dev_tools_hot_reload =True, threaded=True)
添加回答
舉報(bào)