4. Working with Dash and Plotly in Jupyter#
import dash
print(dash.__version__)
2.18.2
# Import the Express module from Plotly as px
import plotly.express as px
# Create your first figure with Plotly!
fig = px.line(x=[1, 2, 3, 4, 5], y=[4, 1, 3, 2, 5], title="Hello Plotly!")
# Show the figure
fig.show()
import dash
from dash import dcc, html
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Graph(
id='example-graph',
figure=px.line(x=[1, 2, 3, 4, 5], y=[4, 1, 3, 2, 5], title="Hello Dash!")
)
])
if __name__ == '__main__':
app.run() # Inline
# app.run_server(jupyter_mode='external') # Open in a new window
# app.run(jupyter_mode="tab")
# app.run(jupyter_mode='jupyterlab') # Open in a new tab of Jupyter Lab. Only works in Jupyter Lab.