jupyterhub / binderhub

Run your code in the cloud, with technology so advanced, it feels like magic!
https://binderhub.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.56k stars 390 forks source link

Show a preview for other files than notebooks #1106

Open jtpio opened 4 years ago

jtpio commented 4 years ago

Proposed change

It would be nice if we could show a preview for other files too, for example Python files.

For now opening the jupyterlab-demo Binder automatically downloads the file:

image

https://mybinder.org/v2/gh/jupyterlab/jupyterlab-demo/master?urlpath=lab/tree/notebooks/lorenz.py

Alternative options

An alternative is to not have the file in the url, or to create a notebook with a link to the file to open.

Who would use this feature?

To show a preview for other files (just like for notebooks). The preview for a Python file would be its content (or part of its content).

(Optional): Suggest a solution

Or only show the preview for notebook files to prevent the file download popup.

jtpio commented 4 years ago

It's probably related to the way nbviewer handles files.

betatim commented 4 years ago

This does seem a bit weird (at the very least). When we added the nbviewer preview it was to give us an easy, low maintenance way to have a preview.

I don't think we can change the way nbviewer.jupyter.org is configured and we decided against including a nbviewer instance in BinderHub to generate previews. Maybe there is a way we can prevent the download popup via URL parameters when generating the iframe link?


Longer term I've been wondering what a "second generation" launch page would look like. For example is the a lightweight JS library that can render ipynb, md, Rmd and "source code" in a pretty way? Maybe we could use that to show a more prominent preview (and one day implement something like edit before launch). Maybe something for a new issue?

jtpio commented 4 years ago

It seems that the download comes from nbviewer directly when it is passed the URL to the Python file, by pasting the following link into the search box: https://github.com/jupyterlab/jupyterlab-demo/blob/master/notebooks/lorenz.py

This would explain why we get it on BinderHub too.

Maybe there is a way we can prevent the download popup via URL parameters when generating the iframe link?

Maybe by only showing the IFrame if the file is a notebook file ending with .ipynb?

Longer term I've been wondering what a "second generation" launch page would look like. For example is the a lightweight JS library that can render ipynb, md, Rmd and "source code" in a pretty way? Maybe we could use that to show a more prominent preview (and one day implement something like edit before launch). Maybe something for a new issue?

And then yes this sounds good (and indeed it can be tracked in a separate issue).

betatim commented 4 years ago

I'd be Ok with either not showing the nbviewer iframe if the "thing" it would show is a file that would trigger a download or reading the nbviewer docs/asking Min if there is a way to prevent the download and get a preview instead.