Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge JupyterDash with Dash #2530

Merged
merged 19 commits into from
Jun 21, 2023
Merged

Merge JupyterDash with Dash #2530

merged 19 commits into from
Jun 21, 2023

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented May 15, 2023

Merge JupyterDash functionality in dash to render dash apps in jupyter notebooks.

Simply run app inside a jupyter cell to render automatically on the cell output:
jupdash

Changed from jupyter dash

  • Default display mode changed to inline.
  • Add mode tab, automatically open the app in a new browser tab.
  • Set the default mode and inline exception options on the jupyter_dash instance:
from dash import jupyter_dash

jupyter_dash.default_mode = "external"
jupyter_dash.inline_exceptions = False

@janosh
Copy link

janosh commented May 16, 2023

Exciting work! Thanks @T4rk1n, looking forward to using this.

@@ -0,0 +1,48 @@
{
"name": "@plotly/dash-jupyterlab",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently published to npm as jupyterlab-dash - is that published version used for anything? Is there a reason to change its name and scoping here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses the tar bundle included in the Python package, that needs to be built the first time you open jupyterlab. Not sure if the npm package is used for anything, the jupyterlab docs says it can be directly to jupyterlab with npm but I am not sure the user really want to do that. https://jupyterlab.readthedocs.io/en/latest/extension/extension_tutorial.html#publishing-your-extension

I changed the name to avoid conflict if jupyter-dash is installed.

Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
dash/_jupyter.py Outdated Show resolved Hide resolved
@@ -39,5 +39,17 @@
page_container,
)
from ._patch import Patch # noqa: F401,E402
from ._jupyter import jupyter_dash # noqa: F401,E402
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this in the main namespace? Will users ever need to use it directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved some options previously in JupyterDash .__init__ or run to be globally settable on the jupyter_dash instance.
You can change the default mode with jupyter_dash.default_mode and disable exception inlining jupyter_dash.inline_exceptions = False.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @LiamConnors to make sure these options get documented

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 just a style point #2530 (comment), this looks great!

@T4rk1n T4rk1n changed the title [WIP] Merge JupyterDash with Dash Merge JupyterDash with Dash Jun 15, 2023
@T4rk1n T4rk1n merged commit 090cef5 into dev Jun 21, 2023
@T4rk1n T4rk1n deleted the jupyter branch June 21, 2023 19:51
cchu70 added a commit to getzlab/AnnoMate that referenced this pull request Jun 26, 2023
@MP-MaximilianLattka
Copy link

Is an additional extension required to be able to open dash as a jupyterlab-tab?

On a clean setup, I'm trying app.run(jupyter_mode="jupyterlab") without success. To clarify, I'm not running jupyter-lab v3, but already v4.

https://dash.plotly.com/dash-in-jupyter#display-modes

I'm uncertain whether to open an issue for my concern.

@Coding-with-Adam
Copy link

hi @MP-MaximilianLattka
We highlight recommend using Dash 2.11 or higher with JupyterLab 3. We have encountered a few issues running Dash with JupyterLab version 4.

@bjlittle
Copy link

bjlittle commented Nov 28, 2023

Hi @Coding-with-Adam,

As @MP-MaximilianLattka mentions above, I'm also having similar issues with dash and the jupyter_mode="jupyterlab" mode, which executes but doesn't open a new tab.

I've simply been attempting to get the minimal dash app to work in this mode, but sadly to no avail.

I've pinned back jupyterlab<4 but this makes no difference.

Can you recommend a combination other than conda create -n dash -c conda-forge dash pandas "jupyterlab<4" that will work for the minimal dash app and for the jupyter_mode=jupyterlab mode?

Many thanks

P.S., Are there other similar live issues that you know of that I can track to monitor progress on this?

@Coding-with-Adam
Copy link

This might be a bug.
@T4rk1n can you please take a quick look? I installed Jupyterlab 3 and ran the app code below. All jupyter modes work except for the jupyter_mode="jupyterlab" . Even after I restart the kernel, it doesn't do anything. It remains stuck as if the code cannot be executed.

from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')

app = Dash(__name__)

app.layout = html.Div([
    html.H1(children='Title of Dash App', style={'textAlign':'center'}),
    dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),
    dcc.Graph(id='graph-content')
])

@callback(
    Output('graph-content', 'figure'),
    Input('dropdown-selection', 'value')
)
def update_graph(value):
    dff = df[df.country==value]
    return px.line(dff, x='year', y='pop')

if __name__ == '__main__':
    app.run(jupyter_mode="jupyterlab")

@bjlittle
Copy link

bjlittle commented Nov 29, 2023

@Coding-with-Adam Also, you'll notice that once you start the app, no jupyter tab is opened, but you can hit the URL of the app in another browser window and it connects and renders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants