How to transform a jupyter notebook into a webapp?

#1

Hello,

I developed an handful of jupyter notebooks to solve a set of small problems. All have the same workflow: upload data, compute something, show a nice report with plots.
I want to share these “tools” with non-technical people so I’d like to streamline a bit the interface (no editing, a nice “start button”, ecc).

What is the preferred way to achieve that? Do you have any advice?

Best regards,
Mario.

1 Like
#2

Hi Mario,

The second two issues can be solved with appmode and ipywidgets. Or possibly even Jupyter book.

Examples



https://hub.mybinder.org/user/gwastro-gwapps-37r8r8mg/apps/gw150914.ipynb

For example of features for Jupyter Book start here.

The documentation on the underlying resources


https://ipywidgets.readthedocs.io/en/stable/index.html

I don’t yet know a good way to handle the first part because presumably you want them to be able to add their own data. Maybe you could have related example data already be there and have a link documenting how to upload and get back to appmode? Or if this is stuff that they can put into a cell and then you can trigger processing via Jupyter Book?

Wayne

#3

I think there are widgets/libraries that let you have a “Upload a file” button as part of your notebook. It has been a long time since I used any of them and neither really knocked my socks of when I did :-/

1 Like
#4

There is also a discussion about a FileUpload widget here: https://github.com/jupyter-widgets/ipywidgets/issues/1542
And the ipyupload package which is already pip installable: https://gitlab.com/oscar6echo/ipyupload

3 Likes
#5

Thank you for you answers, I was not aware of those projects!

The data upload seems to be the main issue. Maybe I am trying to achieve something not really suited for jupyter? In the end I am giving up the Read-Eval-Print-Loop pattern. What if I am willing to rewrite my tools outside jupyter? Is there a way to keep using the same libraries (numpy, holoviews, bokeh, ecc) to create a usable application for non technical users?

#6

There are definitely options outside of Jupyter if you are willing to give up the Read-Eval-Print-Loop pattern, as it sounds like you are.

You could just write a python script that people put alongside their data. You can generate a report other ways and that generation can be part of the script. The main way I have used in the past is via ReportLab because it can do everything and make composited PDFs. But you can go simpler by using Matplotlib and annotation or PIL to control placing the parts of your report.
Or if you want you can make the output go to Plotly I believe. Where the ‘report’ could be a webpage with the resulting plots if that works. I have old example code with composting with ReportLab here.

Although it doesn’t have the report making aspect, the first part of this notebook I have here sort of illustrates putting data alongside a script with sample data and then suggest user to add their data. The goal is just to really get users pointing the script plot_expression_across_chromosomes.py at their data and then they get a plot. The overarching script is stored in a different repo and obtained in the preparation steps. (However, that particular script I haven’t overhauled to my current, clearer coding style. So if you need a model, I’d suggest the one named ‘nucleotide_difference_imbalance_plot_stylized_like_Figure_8_of_Morrill_et_al_2016.py’ available here; the blurb about it at that page tells you how you can run the demo page via MyBinder.)

That type of combination can also be dockerized so they would just need to place their data in a directory that you then tell them how to attach to a Docker container and then trigger the processing with a single command. This example here builds to something like that while teaching about Docker. I say ‘something like that’ because the software triggered isn’t a Python script as far as I know but the idea is the same.

As for giving people a place to put their data with your code, you can go even fancier and make an actual Python-based web app using Django or Flask. Because it is Python, you can use thePython modules that you have mentioned. I have done this on PythonAnywhere with some really simple items before I discovered Jupyter and the MyBinder combination, for examples see http://fomightez.pythonanywhere.com/ammonium_screen/ or http://fomightez.pythonanywhere.com/spartan_fixer/ . However, that adds overhead of learning another ecosystem and adds hosting fees if you are allowing people to process a lot of data. Jupyter allows much more complex interaction between users and your code though without focusing on the overhead of web development. In fact I never quite got around to implementing the upload part and was just working with web forms at the time, as you’ll see if you look at my examples being served from PythonAnywhere.

#7

Does app mode still require containerization for security? Put another way, does app mode allow for arbitrary code execution?

Thanks!

#8

We just had a moment to chat with the QuantStack team about a project they’re working on called Voila (https://github.com/quantstack/voila). It sounds like it’s a good solution for this use-case! @SylvainCorlay could explain more but this is definitely worth checking out.

#9

Another option that just emerged: https://github.com/bentoml/BentoML

Use their webservice wrapping and put a shiny JavaScript webapp before that.

1 Like
#10

appmode is a notebook extension that changes what the UI looks like. This means there is still a full blown server (and kernel) connected to the notebook, which means users can continue to run their own code (if they can figure out how to switch to “edit mode” in appmode)

Something like voila (mentioned by Chris) is better in this case as it actually disables/doesn’t implement some parts of the kernel communications protocol which means that users can’t send code to the kernel. Quick demo: https://mybinder.org/v2/gh/QuantStack/voila/stable?urlpath=voila/tree/notebooks

1 Like
#11

Voila looks great. Thanks!

1 Like