Search code examples
pythonjupyter-notebookprocessingandroid-binder

How to setup a Jupyter-notebook with calysto-processing to run in Binder?


I have running on my own Mac with the caylsto-processing library plugged in so I can run processing scripts in a notebook in a browser tab. But I am trying to be able to run this all in binder, so that I can share my processing scripts with students during class. I created a Github repository and have it linked to a binder, and the binder builds and launches, but the only kernel available is python 3.

I have read that I can include a bunch of configuration files, but I'm new to these and I don't see any examples that bring in the calysto-processing kernel, so I'm unsure on how to proceed.

Screenshot of my binder with the jupyter-notebook with a processing script - but when you click on kernels, the only kernel it shows is python: Screenshot of my binder with the jupyter-notebook with a processing script - but when you click on kernels, the only kernel it shows is python

Any help would be appreciated.


Solution

  • Very good question. Ayman suggestion is good.

    I've just installed calysto_processing and noticed 3 things are necessary:

    1. installing the calysto_processing package via pip,
    2. running install on the calysto_processing package.
    3. installing Processing.

    First point should be easy with requirements.txt.

    I'm unsure what the best option is for the second step (maybe a custom setup.py ?).

    Step 3 feels the trickiest.

    Installing Processing currently isn't supported with apt-get so Dockerfile might be way forward (even through mybinder recommend that only as a last resort).

    Let's assume a Dockerfile would contain all the steps to manually download/install processing (and I'm not super experienced with Docker at the moment btw), it will need to be executed which will require a windowing system to render the Processing window. I don't know how well that plays with Docker, sounds like it's getting into virtual machine territory.

    That being said, looking at the source code right here:

    1. Processing is used only to validate the sketch, and pull syntax errors to display them otherwise.
    2. ProcessingJS is used to actually render the processing code in a <canvas/> element within the Jupyter Notebook

    I'm not sure what the easiest way to run the current calysto_processing in mybinder as is.

    My pragmatic (even hacky if you will) suggestion is to:

    1. fork the project and remove the processing-java dependency (which means might loose error checking)
    2. install the cloned/tweaked version via pip/requirements.txt (pip can install a package from a github repo)

    Update I have tried the above: you can run test kernel here

    ProcessingJS in mybinder online shared Jupyter Notebook

    The source is here and the module is installed from this fork which simply comments out the processing-java part.

    In terms of the mybinder configuration it boils down to:

    • create a binder folder in the repo containing the notebook
    • add requirements.txt which points to the tweaked version of calysto_processing stripped off the processing-java dependency: git+https://github.com/orgicus/calysto_processing.git@hotfix/PJS-only-test
    • add postBuild file which runs install on the calysto_processing module: python -m calysto_processing install --user

    Notes

    • With this workaround java error checking is gone
    • Although Processing syntax is used it's execute as javascript and rendered in <canvas/> using ProcessingJS: this means no processing-java libraries, no threads or other java specific features,(buggy or no 3D),etc. just basic Processing drawing sketches
    • It might be worth looking at replacing ProcessingJS with p5.js and checking out other JS notebooks ? (e.g. Observable or IJavascript)