trungleduc / jupyter_app_launcher

A JupyterLab extension to create custom launcher entries.
https://jupyter-app-launcher.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
53 stars 11 forks source link

Rendering a local HTML file in a Jupyter tab #64

Closed MalloryWittwer closed 1 month ago

MalloryWittwer commented 1 month ago

Hello,

I would like to create a launcher entry to render a locally-built website in a Jupyterlab tab. I'm working with a JupyterHub that spawns user sessions in separate docker containers. Each user has an index.html file saved in their session. My goal is for them to be able to render this index.html file in a jupyter lab tab by clicking on a launch button.

Below are my two attempts at setting up the jp_app_launcher.yaml, either using a url or via a local-server type:

- title: Render local HTML file
  source: file:///home/jovyan/src/_build/html/index.html
  type: url
  catalog: Commands
  args:
    sandbox: [ 'allow-same-origin', 'allow-scripts', 'allow-downloads', 'allow-modals', 'allow-popups']
    referrerPolicy: ['no-referrer']
    createNewWindow: false

- title: Render HTML website
  source: http://localhost:9000/
  type: local-server
  catalog: Commands
  args:
    - python3
    - -m
    - http.server
    - '9000'
    - --directory=/home/jovyan/src/_build/html/
    - --bind=127.0.0.1

The first option (url) doesn't work because the browser isn't allowed to render local files, as I understand it. The second option (local-server) seems more promising. The command python -m http.server works; the process appears in the "Launcher Application" list, the web server is running, and curl http://localhost:9000/ returns indeed the correct HTML (command sent from the user's session, so inside the docker container).

Despite that, the launcher still throws a 500 - Internal Server Error when opening a new jupyter tab. Looking in the logs, I also see a ConnectionRefusedError: [Errno 111] Connection refused error.

Any help would be appreciated. Thank you very much!

trungleduc commented 1 month ago

Hi, can you try to use the PORT variable, like in this example:

- title: Streamlit example
  description: Example of opening a streamlit app
  source: http://localhost:$PORT/
  cwd: ./
  type: local-server
  args:
    - streamlit
    - run
    - st_app.py
    - --server.headless=true
    - --server.port=$PORT
  catalog: Another catalog

jupyter_app_launcher will define this variable and do the routing job

MalloryWittwer commented 1 month ago

Thank you, indeed using the $PORT variable seems to have solved my problem. For the record, the modified code is:

- title: Render HTML website
  source: http://localhost:$PORT/
  type: local-server
  catalog: Commands
  args:
    - python3
    - -m
    - http.server
    - '$PORT'
    - --directory=/home/jovyan/src/_build/html/
    - --bind=127.0.0.1