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

Error when trying to run a dashboard in jupyterHub #124

Open
antonymilne opened this issue Oct 25, 2023 · 14 comments
Open

Error when trying to run a dashboard in jupyterHub #124

antonymilne opened this issue Oct 25, 2023 · 14 comments
Assignees

Comments

@antonymilne
Copy link
Contributor

Does anyone know anything about the error <ContextVar name='callback_context' at 0x7f78465b2f90> when trying to run a dashboard in jupyterHub?

Originally posted by @LucaYoy in #109 (comment)

@antonymilne antonymilne changed the title Does anyone know anything about the error <ContextVar name='callback_context' at 0x7f78465b2f90> when trying to run a dashboard in jupyterHub? Error when trying to run a dashboard in jupyterHub Oct 25, 2023
@antonymilne
Copy link
Contributor Author

@LucaYoy Please could you give some more information about exactly when this occurs and what your notebook contains?

@LucaYoy
Copy link

LucaYoy commented Oct 25, 2023

I essentially have a data frame named data which contains features for a clustering problem and I'm trying to plot the distributions of each of these features in a dashboard.

my code cell containing the code is:

page = vm.Page(
    title = 'Distributions before normalization',
        components = [
        vm.Graph(id='#1 dist',figure=px.histogram(data,x='#1')),
        vm.Graph(id='#2 dist',figure=px.histogram(data,x='#2')),
        vm.Graph(id='#3 dist',figure=px.histogram(data,x='#3')),
        vm.Graph(id='#4 dist',figure=px.histogram(data,x='#4'))],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run(jupyter_mode="inline")

where "#1" is the first feature etc. when i run this i get the error described above.
The error is coming from Vizro().build(dashboard).run(jupyter_mode="inline")

@huong-li-nguyen
Copy link
Contributor

Hey @LucaYoy ,

could you let me know what dash and flask version you use? I've tried to run your example with some fake data and this seemed to work fine for me, so could you try the following:

  1. Restart your Kernel and re-run the dashboard - does it still give you that error?
  2. Could you try the example below and see if it works for you? If it does work, then it might be caused by your data, so it would be good to know the data format and types. The jupyter_mode="inline" should not be required anymore if you use Dash 2.11 or higher.
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro

df = px.data.tips()
page = vm.Page(
    title = 'Distributions before normalization',
        components = [
        vm.Graph(id='#1 dist',figure=px.histogram(df, x="total_bill")),
        vm.Graph(id='#2 dist',figure=px.histogram(df, x="tip")),
        vm.Graph(id='#3 dist',figure=px.histogram(df, x="size"))],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
  1. If you run this code section here to clear everything up and then re-run your dashboard - does it still give you that error?
import dash
from vizro.managers import data_manager, model_manager

def reset_state():
    data_manager._reset()
    model_manager._reset()
    dash._callback.GLOBAL_CALLBACK_LIST = []
    dash._callback.GLOBAL_CALLBACK_MAP = {}
    dash._pages.PAGE_REGISTRY.clear()
    dash._pages.CONFIG.clear()
    dash._pages.CONFIG.__dict__.clear()

@LucaYoy
Copy link

LucaYoy commented Oct 25, 2023

Hi @huong-li-nguyen , im running vizro 0.1.4 and dash 2.13.0

I already tried 1. and 3. and it still gives me that error. I have also made a new notebook and run 2. and sadly I get same error. My team and i use this platform which has jupyter and and other solutions build into it like airflow etc. maybe that is the problem not sure.

@huong-li-nguyen
Copy link
Contributor

Hey @LucaYoy,

interesting - could you tell us more about the platform?

The other thing, could you try if a standard Dash app works fine in the environment? Here is an example, that you could try out:

from dash import Dash, html, dcc
import plotly.express as px

df = px.data.tips()

app = Dash(__name__)
app.layout = html.Div([
    html.H1('Test App'),
    html.Div([
        dcc.Graph(id='#1 dist', figure=px.histogram(df, x="total_bill")),
        dcc.Graph(id='#2 dist', figure=px.histogram(df, x="tip")),
        dcc.Graph(id='#3 dist', figure=px.histogram(df, x="size"))
    ]),
])


if __name__ == '__main__':
    app.run()

@LucaYoy
Copy link

LucaYoy commented Oct 26, 2023

@huong-li-nguyen the dash code above doesn't throw any error however the webpage displayed in jupyter has written 127.0.0.1 refused to connect.. Regarding a platform, it is basically a virtual disk - mount where for example both jhub and airflow hit. Let me get back to you when i can tell you in a bit more detail about the platform.

Ye as i said its a virtual machine pretty much. The only thing is that we cant make an external server because it might get blocked through proxy, so only way for the dashboard to be seen is in the output cell in the notebook, however thats when i get the error

@huong-li-nguyen
Copy link
Contributor

Interesting,

could you update the run call to the following:

Vizro().build(dashboard).run(host='localhost', port=8005) and then access via localhost: 8005 or
Vizro().build(dashboard).run(host='0.0.0.0', port=8005) and then access via http://0.0.0.0:8005/

Does any of that work?

@LucaYoy
Copy link

LucaYoy commented Oct 27, 2023

@huong-li-nguyen, tried for both the dash app and vizro

  1. For dash app it says 'localhost refused to connect'.
  2. For dash app http://0.0.0.0:8005/ is blocked through proxy (for some reason...)

For vizro when trying both things i still get the error <ContextVar name='callback_context' at 0x7f5ebc7276d0>

@huong-li-nguyen
Copy link
Contributor

Hey @LucaYoy ,

thanks for getting back!

If this is the case, I don't think it's related to Vizro but some difficulties accessing the port on the platform.

Could you first try running this at the beginning of the notebook:

from dash import jupyter_dash
jupyter_dash.infer_jupyter_proxy_config()

I was also just scanning through the Dash support channels and this might help if the above doesn't work: plotly/dash#2629

If the issue still can't be resolved, then I would ask you to reach out to the Dash support channels directly as they will be able to help you with any issue related to jupyter_dash

I hope one of the fixes work 🤞

@LucaYoy
Copy link

LucaYoy commented Oct 27, 2023

Ye, when running the above i get error 'IPythonKernel' object has no attribute 'get_parent'

@huong-li-nguyen
Copy link
Contributor

huong-li-nguyen commented Oct 27, 2023

Hey @LucaYoy ,

there seems to be an open issue on jupyter_dash for that specific error as well: plotly/jupyter-dash#100

I would suggest following the discussion there and eventually following up with them, as the current issue seems to be a JupyterDash one.

@LucaYoy
Copy link

LucaYoy commented Oct 27, 2023

ye i guess it all boils down to some dash bug since vizro is build with dash ? From what i see the issues above are not really resolved yet :(

probably also the security measures my company have in place dont help much since it blocks so many things

@huong-li-nguyen
Copy link
Contributor

Yes, exactly - vizro is build on top of dash.

I try to keep an eye open on the dash issues as well, and hopefully they'll be able to fix it soon 🤞

@antonymilne
Copy link
Contributor Author

antonymilne commented Jan 22, 2024

@LucaYoy I think we might have been able to solve this - see #175 (comment). Do let me know if either of the fixes given there work for you,.

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

No branches or pull requests

3 participants