Creating startup files for jupyter notebooks in binder

I am very new to binder, so please forgive this very newbie question. I do have Jupyter notebook up and running on mybinder, which is exciting! But, I would like to refine it a bit.

My overall goal is to create a web page with interactive matplotlib graphics and animations that will be as easy as possible for users to use. Although it may seem trivial, I would like users to not even have to execute a command already in the notebook when they open it. If this was a notebook on a local machine, I could put a script in the startup directory, which I have identified as:
Is there a way that I can add a file to this directory, or otherwise control the jupyter configuration on binder?
Thanks in advance for any suggestions.

We have config files called postBuild and start that are basically bash scripts that could be used to perform tweaks to the environment before your user arrives.

I would also look into voila for generating the webpage from the Notebook


Thanks very much. So just so I am clear, do I add a file called postBuild to my repository, with a bash script that creates the directory structure
and then put my python startup script there? What directory does the bash script run from?

I will definitely look into Voila. My plan had been to follow the approach described here:

But, it looks like Voila might be simpler.
Thanks again,

There is also Jupyter Book which uses Sphinx to host the static webpages and supports mybinder buttons for interactivity as well. They’ve just undergone a huge rebuild and its great to use

As far as the postBuild script goes, yes just add it to your repo and put in the commands you’d like to run in it. I’m not sure which directory it executes in though so may require some trial and error to get working.

1 Like

I think that postBuild runs relative to \home\jovyan.

If you want to set persistent environment variables that are available in the MyBinder container, or run commands on startup, you need to do this in the start file, which should take the form:


# set environment variables
# ...

# execute run commands
# ...

exec "$@"

Thanks for these suggestions. I am able to get a postBuild file to work and to create a startup python script, which runs when a notebook is opened. The catch is that the output of the script isn’t displayed in the notebook. After a bit digging, I understand that is just the way things are when commands are executed upon opening a notebook. It’s fine for loading modules or setting the notebook configuration, but not for what I need.

So, I’ve been working with Voila for a bit, on my local machine. This looks very nice, but I am running into a problem there, too. I can make ipywidgets appear and work, but matplotlib output doesn’t appear.

I will start a new thread on the Voila problem.

Thanks again,