neurohackademy / nh2020-jupyterhub

hub.neurohackademy.org: Deployment config, docker image, documentation.
16 stars 27 forks source link

instructor request: HTML rendering from JupyterLab #98

Closed consideRatio closed 4 years ago

consideRatio commented 4 years ago

@oesteban hope participants could be able to view a set of HTML files from JupyterLab's HTML viewer. There are some challenges and I'll see if I think we can overcome them.

JavaScript - status: disabled (workaround possible)

It's worth nothing that JavaScript in the HTML file viewed using the JupyterLab HTML viewer isn't allowed. I'm not sure about this topic in general but just wanted to make a note about that.

<noscript>
    <h1 class="text-danger"> The navigation menu uses Javascript. Without it this report might not work as expected </h1>
</noscript>

Note that instead of using JupyterLab's HTML viewer, it is possible to view the Jupyter Notebook's servers own HTML viewer, then JavaScript is allowed, this can be done with a link like below.

https://hub.neurohackademy.org/hub/user-redirect/view/data/openneuro/ds000114/derivatives/fmriprep-20.2.0rc0/fmriprep/sub-05.html

Relative file references - status: ok

The image reference src="./sub-05/figures/sub-05_dseg.svg", when viewed with JupyterLab's HTML viewer, translated to a web request sent out from my browser to https://hub.neurohackademy.org/user/consideratio/files/data/openneuro/ds000114/derivatives/fmriprep-20.2.0rc0/fmriprep/sub-05/figures/sub-05_dseg.svg.

This worked as we hoped actually, as /user/consideratio was prepended, and /files/data/openneuro/ds000114/... etc was prepended to represent the ./ in the actual link. This was not possible in earlier version of JupyterLab.

Access to referenced file - status: 403 error

The crux is that when our browsers parse the HTML and request the file https://hub.neurohackademy.org/user/consideratio/files/data/openneuro/ds000114/derivatives/fmriprep-20.2.0rc0/fmriprep/sub-05/figures/sub-05_dseg.svg, it turns out that we get a 403: Forbidden error from the Jupyter notebook server. Its worth noting that JupyterHub is not involved with this, and not even JupyterLab at this point.

[W 2020-07-28 07:30:01.453 SingleUserNotebookApp handlers:414] Blocking request with no referer
[W 2020-07-28 07:30:01.453 SingleUserNotebookApp web:1782] 403 GET /user/consideratio/files/data/openneuro/ds000114/derivatives/fmriprep-20.2.0rc0/fmriprep/sub-05/figures/sub-05_ses-test_task-linebisection_desc-bbregister_bold.svg (10.60.32.16): Blocking request from unknown origin

This is a response following this line of code in the jupyter notebook server.

(I'll update with more information as I continue thinking about this)

Using jupyter-server-proxy

We could perhaps opt to not use the HTML viewer as part of JupyterLab, but an actual dedicated web-server by using jupyterhub/jupyter-server-proxy.

In #108 I've installed the jupyter-server-proxy's labextension, which could if we add configuration, allow users to get a nice button in the launcher to startup a server. To trial this yourself:

vim ~/.jupyter/jupyter_notebook_config.py

Add the following to the file as a demonstrative example.

c.ServerProxy.servers = {
  'test-server': {
    'command': ['python3', '-m', 'http.server', '{port}'],
  }
}

Hopefully, you should have a button like this showing up alongside the JupyterLab launcher buttons.

image

NOTE: You must have started your JupyterHub server with the latest image, which followed #108 being merged.

consideRatio commented 4 years ago

@oesteban @satra @alexhuth see the last section of the post above. It will be available on in some minutes on the hub. I'm trying it out and reporting back.

If this works, and you want to make use of this, I suggest that you figure out what you would like to make available to all users in the jupyter_notebook_config.py, and I can make them get access to that.

consideRatio commented 4 years ago

@oesteban it did the trick! I tried it for your use case. This is the result.

oesteban

oesteban commented 4 years ago

Amazing! Thanks!

On Wed, Jul 29, 2020 at 5:43 PM Erik Sundell notifications@github.com wrote:

Closed #98 https://github.com/neurohackademy/nh2020-jupyterhub/issues/98 via #109 https://github.com/neurohackademy/nh2020-jupyterhub/pull/109.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/neurohackademy/nh2020-jupyterhub/issues/98#event-3599670869, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAESDRUOATLVERI324QBP53R6A7RHANCNFSM4PKH2KHA .

satra commented 4 years ago

thanks @consideRatio

consideRatio commented 4 years ago

tmp-demo-websites-in-hub

consideRatio commented 4 years ago

This was @alexhuth solution - to generate a link and start a webserver with a terminal command using ! from a cell.

image