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

css url of Terminal widget not correct in jupyter lab preview #2643

Closed
MarcSkovMadsen opened this issue Aug 18, 2021 · 8 comments · Fixed by #3289
Closed

css url of Terminal widget not correct in jupyter lab preview #2643

MarcSkovMadsen opened this issue Aug 18, 2021 · 8 comments · Fixed by #3289
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Aug 18, 2021

panel 0.12.1

image

It's trying to find the css at https://DOMAIN/mt-workspace/user/masma/panel-preview/render/shared/static/extensions/panel/bundled/terminal/[email protected]/css/xterm.css

But it's actually served at https://DOMAIN/mt-workspace/user/masma/panel-preview/static/extensions/panel/bundled/terminal/[email protected]/css/xterm.css

image

This issue is related to #2545

@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Aug 18, 2021
@MarcSkovMadsen
Copy link
Collaborator Author

I'm trying to understand what happens and why.

image

@MarcSkovMadsen
Copy link
Collaborator Author

If I go to https://DOMAIN/mt-workspace/user/masma/panel-preview/render/shared/Untitled1.ipynb

image

and look at the page source I see the below. I.e. it looks like js is served corrected but css is not.

image

<html>
<body>
<!--StartFragment-->

<!DOCTYPE html>
--
  | <html lang="en">
  |  
  | <head>
  |  
  | <meta charset="utf-8">
  | <title>Panel Application</title>
  |  
  |  
  |  
  |  
  | <link rel="stylesheet" href="static/extensions/panel/bundled/terminal/[email protected]/css/xterm.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/widgets.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/markdown.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/loading.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/json.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/card.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/dataframe.css" type="text/css" />
  | <link rel="stylesheet" href="/mt-workspace/user/masma/panel-preview/static/extensions/panel/css/alerts.css" type="text/css" />
  | <style>
  |  
  | .bk.pn-loading.arcs:before {
  | background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBzdHlsZT0ibWFyZ2luOiBhdXRvOyBiYWNrZ3JvdW5kOiBub25lOyBkaXNwbGF5OiBibG9jazsgc2hhcGUtcmVuZGVyaW5nOiBhdXRvOyIgdmlld0JveD0iMCAwIDEwMCAxMDAiIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIj4gIDxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjMyIiBzdHJva2Utd2lkdGg9IjgiIHN0cm9rZT0iI2MzYzNjMyIgc3Ryb2tlLWRhc2hhcnJheT0iNTAuMjY1NDgyNDU3NDM2NjkgNTAuMjY1NDgyNDU3NDM2NjkiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCI+ICAgIDxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgdHlwZT0icm90YXRlIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgZHVyPSIxcyIga2V5VGltZXM9IjA7MSIgdmFsdWVzPSIwIDUwIDUwOzM2MCA1MCA1MCI+PC9hbmltYXRlVHJhbnNmb3JtPiAgPC9jaXJjbGU+PC9zdmc+")
  | }
  |  
  | </style>
  |  
  |  
  |  
  | <script type="text/javascript" src="/mt-workspace/user/masma/panel-preview/static/extensions/panel/bundled/terminal/[email protected]/lib/xterm.js"></script>
  | <script type="text/javascript" src="/mt-workspace/user/masma/panel-preview/static/extensions/panel/bundled/terminal/[email protected]/lib/xterm-addon-web-links.js"></script>
  | <script type="text/javascript" src="/mt-workspace/user/masma/panel-preview/static/js/bokeh.min.js?v=36c1f44e80c69a608452746fd99d7b45d5d61daff899a8c1ff778875d4ffa3710cec84b8ff7e18dd077026bd90830d8c46741a3d492252d1e291d4e254078e8d"></script>
  | <script type="text/javascript" src="/mt-workspace/user/masma/panel-preview/static/js/bokeh-widgets.min.js?v=afa4dcefab2d124480814f7ec2dbd6a60dea97f575c9c34bb50526c99053d7dccf1c23c66b17055b8cc27533be74556fbbe0677a3a9a5bfe84f8a12aa8a2306d"></script>
  | <script type="text/javascript" src="/mt-workspace/user/masma/panel-preview/static/js/bokeh-tables.min.js?v=69a2fcb5cdc0a04e5d4d898d217b3e8bf3ae59d039cf14d8f6d031f26a88100cec4f7cc55d6e4a81b41dc140f57a0b077a9e08deaed799a339d69d0ada9beed8"></script>
  | <script type="text/javascript" src="/mt-workspace/user/masma/panel-preview/static/extensions/panel/panel.min.js"></script>
  | <script type="text/javascript">
  | Bokeh.set_log_level("info");
  | </script>

<!--EndFragment-->
</body>
</html>

@MarcSkovMadsen
Copy link
Collaborator Author

My guess is that its the lines of code below that causes problems

image

@MarcSkovMadsen MarcSkovMadsen changed the title Jupyter Preview not serving css files correctly on Jupyter Hub Jupyter Preview not serving css files correctly on Jupyter Hub and Binder Aug 18, 2021
@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Aug 18, 2021

Its the same problem on Binder. To reproduce open https://mybinder.org/v2/gh/holoviz/panel/master?urlpath=lab/tree/examples

and create a new jupyter notebook with

import sys
import uuid
import logging
import panel as pn
import bokeh
from panel.io.jupyter_server_extension import url_path_join

pn.extension("terminal", sizing_mode='stretch_width')
pn.Column(
    pn.__version__,
    pn.__file__,
    pn.state.base_url,
    pn.state.rel_path,
    pn.state.cache.get("handlers", "not included"),
    str(bokeh.embed.bundle.extension_dirs),
    url_path_join(pn.state.rel_path, r"panel-preview/static/(.*)"),
    pn.widgets.Terminal(),
).servable()

Open the preview and notice the problem

image

@MarcSkovMadsen
Copy link
Collaborator Author

Do you know why the terminal css does not get the base_url as prefix or where to look for the explanation @philippjfr ?

image

@MarcSkovMadsen MarcSkovMadsen changed the title Jupyter Preview not serving css files correctly on Jupyter Hub and Binder css urls of widgets not correct on Jupyter Hub and Binder Preview. Aug 18, 2021
@MarcSkovMadsen MarcSkovMadsen changed the title css urls of widgets not correct on Jupyter Hub and Binder Preview. css url of Terminal widget not correct on Jupyter Hub and Binder Preview. Aug 18, 2021
@MarcSkovMadsen MarcSkovMadsen added this to the 0.12.2 milestone Aug 18, 2021
@MarcSkovMadsen MarcSkovMadsen removed the TRIAGE Default label for untriaged issues label Aug 18, 2021
@MarcSkovMadsen MarcSkovMadsen changed the title css url of Terminal widget not correct on Jupyter Hub and Binder Preview. css url of Terminal widget not correct in jupyter lab preview Aug 22, 2021
@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Aug 22, 2021

I can see it does not work locally either

image

The css file is served though at http://localhost:8888/panel-preview/static/extensions/panel/bundled/terminal/[email protected]/css/xterm.css

image

@MarcSkovMadsen
Copy link
Collaborator Author

If I make the change

image

It works

image

My guess is that some of the other loops in that function also need the state.rel_path/ prepended.

@philippjfr philippjfr modified the milestones: 0.12.2, v0.12.x Sep 20, 2021
@MarcSkovMadsen
Copy link
Collaborator Author

This is a fix that has been working for me for months now

def _fix_jupyter_preview():
    """ Fixes https://github.com/holoviz/panel/issues/2643"""
    
    @property
    def css_files(self):
        if pn.state.rel_path:
            files = [f'{pn.state.rel_path}/{file}' for file in super(pn.io.resources.Resources, self).css_files]
        else:
            files = super(pn.io.resources.Resources, self).css_files
        for model in param.concrete_descendents(pn.reactive.ReactiveHTML).values():
            if hasattr(model, '__css__'):
                for css_file in model.__css__:
                    if css_file not in files:
                        files.append(css_file)

        for cssf in config.css_files:
            if os.path.isfile(cssf) or cssf in files:
                continue
            files.append(cssf)
        if self.mode == 'server':
            if pn.state.rel_path:
                dist_dir = f'{pn.state.rel_path}/{LOCAL_DIST}'
            else:
                dist_dir = LOCAL_DIST
        else:
            dist_dir = CDN_DIST
        for cssf in glob.glob(str(DIST_DIR / 'css' / '*.css')):
            if self.mode == 'inline':
                break
            files.append(dist_dir + f'css/{os.path.basename(cssf)}')
        return files

    pn.io.resources.Resources.css_files = css_files

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