1 回答
TA贡献1963条经验 获得超6个赞
任何可用的 Dash 应用程序都可以通过JupyterLab启动,并使用问题中描述的设置,方法是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在其自己的选项卡中进行选择,只需按照以下简单步骤操作:
更改以下行
# 1
import dash
# 2
app = dash.Dash()
# 3
app.run_server(debug=True,
use_reloader=False # Turn off reloader if inside Jupyter
)
对此:
# 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 中内联启动 Dash :
但您也可以mode='external'
启动 Dash 它自己的选项卡:
您可以设置mode='external'在默认浏览器中启动它。
经过更改的完整代码:'
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)
添加回答
举报