ideonate / cdsdashboards

JupyterHub extension for ContainDS Dashboards
https://cdsdashboards.readthedocs.io/
Other
200 stars 38 forks source link

Wrong path for static files if jupyterhub is under a subpath #61

Closed mohammedi-haroune closed 3 years ago

mohammedi-haroune commented 3 years ago

Describe the bug

We have Jupyterhub under /notebook/jupyter in our MLOps platfor https://iko.ai/notebook/jupyter which causes this relative URL to point to a wrong URL and results in select elements not rendered properly, see the screenshot below https://github.com/ideonate/cdsdashboards/blob/8cb741f8bdd5cf143e95d004e9ece211ae1be479/share/cdsdashboards/templates-common/editdashboard.html#L238

This only happens in the new dashboard page but not the edit page because the edit page URL is notebook/jupyter/hub/dashboards/[APP_NAME]/edit whereas the new page URL is notebook/jupyter/hub/dashboards-new

../../dashboards-static/xxxxx in the edit page will point to notebook/jupyter/hub/dashboards-static/xxxxx but it'll point to notebook/dashboards-static/xxxxx in the new dashboard page.

To Reproduce

  1. Put Jupyterhub under a subpath using a reverse proxy like nginx, say /notebook/jupyter
  2. Go to the new dashboard page

Screenshots

Screenshot from 2021-04-11 14-04-46

Configuration

from cdsdashboards.app import CDS_TEMPLATE_PATHS
from cdsdashboards.hubextension import cds_extra_handlers

c.JupyterHub.template_paths = CDS_TEMPLATE_PATHS
c.JupyterHub.extra_handlers = cds_extra_handlers

c.JupyterHub.allow_named_servers = True
c.CDSDashboardsConfig.builder_class = 'cdsdashboards.builder.kubebuilder.KubeBuilder'

# # Add `start.sh` to switch to NB_USER before running the command
c.VariableMixin.default_presentation_cmd = ['start.sh', 'python3', '-m', 'jhsingle_native_proxy.main']

# Options to remove Named Server / Dashboard sections for users on their home page. 
# You can remove the named server section and/or the new bottom section where 
# servers started to act as dashboards are hidden.
c.JupyterHub.template_vars = {
    'cds_hide_user_named_servers': True,
    'cds_hide_user_dashboard_servers': False,
}

# Specify how to name dashbaord servers
c.CDSDashboardsConfig.server_name_template = 'iko-{urlname}'

# Control whether ‘All Users’ or ‘Selected Users’ is selected by default on the ‘New Dashboard’ page.
c.CDSDashboardsConfig.default_allow_all = False

# Show Spawner User Options Form before creating a dashboard
c.CDSDashboardsConfig.spawn_default_options = False

c.CDSDashboardsConfig.presentation_types = ['voila', 'streamlit', 'plotlydash', 'bokeh']

from cdsdashboards.hubextension.spawners.variablekube import VariableKubeSpawner

class CustomKubeSpawner(VariableKubeSpawner):
    "Our custom KubeSpawner implementation"
    pass

c.JupyterHub.spawner_class = CustomKubeSpawner
danlester commented 3 years ago

Thank you for noting this. To clarify, let me explain what happens on a regular JupyterHub (configured to serve at the root URL).

The relevant dashboard URLs are:

NEW: https://myjupyterhub.net/hub/dashboards-new EDIT: https://myjupyterhub.net/hub/dashboards//edit

A built-in feature of JupyterHub is that it redirects otherwise-unknown URLs at / to /hub/.

So https://myjupyterhub.net/dashboards-static/components/jquery.easytabs.js redirects to https://myjupyterhub.net/hub/dashboards-static/components/jquery.easytabs.js

On the edit dashboard page, the relative URL to the static files is accurate. On the new dashboard page it is 'wrong' but gets redirected by JupyterHub.

So in fact the relative URL is no more 'correct' for a regular JupyterHub as it is for yours, but for some reason this redirect functionality isn't working on yours.

I'm not sure why, or whether that matters... I have changed the code in master to use {base_url} directly instead of the relative URL. This is more consistent with the other URLs used in the templates, and hopefully avoids your problem too.

mohammedi-haroune commented 3 years ago

The bug is fixed with the latest commit https://github.com/ideonate/cdsdashboards/commit/2792b165db0d5ed794d25547895509d07b2c4a4c. Thanks.

wmalara commented 3 years ago

Hi, there's also a problem with the address a user is redirected to when accessing a dashboard. I believe this line should be changed to: return self.redirect(url_path_join(self.settings["base_url"], "user", dashboard_user.name, dashboard.final_spawner.name))

mohammedi-haroune commented 3 years ago

Hi, there's also a problem with the address a user is redirected to when accessing a dashboard. I believe this line should be changed to: return self.redirect(url_path_join(self.settings["base_url"], "user", dashboard_user.name, dashboard.final_spawner.name))

Yes, you're right. I had that a couple of times but I couldn't understand when it does happen

danlester commented 3 years ago

Thank you @wmalara and @mohammedi-haroune I've fixed these in 0.5.3, just released.

dealmeida-h commented 1 year ago

I know that the issue is closed, but I'm still seeing something similar in v.0.6.3. I'm trying to access a js in a folder called static at the root of my ipynb, the path is correctly loaded in the editor (and also in voilà, but only if my home server is running). When I look at the console, I see that the applet is looking for the path under /hub/static/path_to_the_js/. Is there a way to pack the static folder with the voila dashboard (like passing the --static flag to voila command line)?

Thanks.