1: The most reliable way is to write a notebook extension. For example I’ve got an extension that automatically runs all notebook cells if ?autorun=true
is in the URL query (it also does other stuff):
Relevant bit of code:
Though note I’m definitely not an expert in writing extensions, so there may be a better way to do this. In any case you should be able to find a way to execute just the first cell.
Edit: It looks like your first cell is executed automatically when run locally because your notebook is trusted, by default notebooks are untrusted since executing arbitrary HTML/Javascript is a security risk:
- The Jupyter Notebook — Jupyter Notebook 5.7.6 documentation
- Security in the Jupyter notebook server — Jupyter Notebook 5.7.6 documentation
2: Linking directly to a mybinder notebook is not as easy as copying and pasting the URL, because each launch on mybinder gets a different URL to the running server. Instead you need to take the URL for launching the binder repo, and and a ?filepath=
or ?urlpath=
E.g. https://mybinder.org/v2/gh/projectmesadata/cropyield/c1e3df46799ca8e3cf9afc5491fcc7a0251efb4b?filepath=Crop%20Yield%20-%20Data%20Download%20(must%20run%20first)-Interactive.ipynb
launches a new binder instance and loads Crop Yield - Data Download (must run first)-Interactive.ipynb
mybinder has some extensions to make this easier, if you’ve opened a notebook clicking the Binder
button should give you a shareable URL: