nebari-dev / nebari

🪴 Nebari - your open source data science platform
https://nebari.dev
BSD 3-Clause "New" or "Revised" License
275 stars 88 forks source link

Importing `geopandas` prevents `panel` from rendering `servable()` components #2562

Open alaws-USGS opened 2 months ago

alaws-USGS commented 2 months ago

Describe the bug

When a file, either .py or .ipynb, has the following line in it, import geopandas as gpd, it gives the following error when trying to preview the Panel app:

Error Message: The Panel application being served did not serve any contents. Ensure you mark one or more Panel components in your notebook or script with .servable(), e.g. pn.Row('Hello World!').servable().

It also does not render when you create an app and start an instance from the landing page.

Testing with another app not using geopandas allows it to render.

Expected behavior

The Panel app to render.

OS and architecture in which you are running Nebari

Linux/AWS EC2

How to Reproduce the problem?

import geopandas as gpd
import panel as pn

pn.Row(pn.pane.Markdown("Some text")).servable()

Command output

No response

Versions and dependencies used.

channels:

Compute environment

AWS

Integrations

No response

Anything else?

No response

Adam-D-Lewis commented 1 month ago

Hi @alaws-USGS, thanks for opening an issue. I'm curious if you've tried to reproduce this locally (not on Nebari). If you are able to reproduce locally, then it suggests the issue is not Nebari specific and the fix may need to be with panel or geopandas or one of the other dependencies.

alaws-USGS commented 1 month ago

Hi @Adam-D-Lewis, I have deployed the same app locally and have not been able to replicate the same issue. I also perused both the panel and geopandas repos and not found a mention of this issue.

Adam-D-Lewis commented 1 month ago

Hi @Adam-D-Lewis, I have deployed the same app locally and have not been able to replicate the same issue. I also perused both the panel and geopandas repos and not found a mention of this issue.

Thank you @alaws-USGS. I have seen some problems with visualization libraries used on Nebari. More info is here. I was able to resolve by pinning several dependencies (ipympl, jupyterlab, jupyterlab_widgets, jupyterlab_server, jupyter_client, ipykernel) to match up with Nebari's jupyterlab image. Be aware that the versions pinned in that issue are no longer the correct versions in the latest version of Nebari. I'm not sure this is the solution to this issue, but would be the first thing I'd recommend to try.

alaws-USGS commented 1 month ago

HI @Adam-D-Lewis, I read your suggestion for the fix and thank you for sharing that. I believe we are using a version of Nebari that matches one of those two so it should hopefully be seamless! I will also report back on what the results are.

I want to echo what you said in your issue and say that this is not something a Nebari user should have to hunt down and manually adjust. I believe that it needs to be addressed in order to make Nebari production-ready.

Adam-D-Lewis commented 1 month ago

I want to echo what you said in your issue and say that this is not something a Nebari user should have to hunt down and manually adjust. I believe that it needs to be addressed in order to make Nebari production-ready.

I agree it's not ideal. There are a few potential solutions I've learned about recently that I would like to test soon - https://github.com/nebari-dev/nebari/issues/2261#issuecomment-2231346756.

kcpevey commented 1 month ago

You mentioned "Panel Preview" so I'm wondering if you are seeing this error when viewing through the Jupyter Notebook "Panel Preview" button? Does it render in a notebook cell?

I have had issues with the Panel Preview button on Nebari. I never tracked down the issue - it was working for me at one point, then it stopped working on my project. I haven't gone back to test with other projects/environments yet.

Also, I dont think this is related, but just in case - I've had some issues with cache when using Panel on Nebari that cause the render to fail in the notebook. You might want to check that out?

kcpevey commented 1 month ago

I noticed you didn't load the panel extension in the notebook. You will definitely need to add that.

I tried building your environment but its very heavy and is still building after 45 minutes took 69 minutes to build, so I made a smaller one for testing:

channels:
  - conda-forge
dependencies:
  - python=3.10
  - geopandas
  - panel
  - param
  - ipykernel

In a Notebook, if I add the pn.extension(), it will render

image

I have noticed a race condition in the past where the pn.extension() call must be made in a separate cell. Not sure if that's still an issue, but just something to be aware of.

All that said, I tried to the Panel Preview button in the notebook and that did NOT work. The preview pane itself is showing nebari.quansight.dev refused to connect. and the js console is showing the error: Refused to frame 'https://nebari.quansight.dev/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".

I removed the geopandas import and I'm seeing the same thing. I think this issue boils down to Panel Preview not working on Nebari, which looks like it may be a security issue within Jupyter.

krassowski commented 1 month ago

JupyterHub 4.1 introduced pretty restrictive CSP. In principle we can change CSP with c.JupyterHub.tornado_settings traitlet.

For reference:

krassowski commented 1 month ago

Here is a related upstream issue:

Quoting:

This is required for inter-user security on single-domain deployments, but can be safely disabled with per-user subdomains.

Nebari should implement per-user domains and then all these restrictions can be safely lifted.

kcpevey commented 1 month ago

I have moved the issue of Panel Preview being unavailable to its own issue.