I have a use case in which I have a notebook intended for use by non-programmers. All they have to do is make sure all of the cells run. I’d like to get the last cell to write an HTML copy of the notebook to disk without the user needing to modify anything in the cell.
With a regular notebook, my initial attempt was to use JavaScript to discover the notebook path…
%%javascript
Jupyter.notebook.kernel.execute("window_loc = '" + window.location + "'")
…extract the file name…
current_file: str = window_loc.split("/")[-1]
…and then issue bash commands to convert the file.
!jupyter nbconvert $current_file --to html --output=$my_custom_output_path --output-dir=$my_out_dir
…where $my_custom_output_path
and $my_out_dir
are generated on the fly from notebook content.
This has proven brittle, insofar as the HTML copies were sometimes incomplete. Moreover, the same approach doesn’t seem to work in JupyterLab. Has anyone discovered a single language answer to this problem (ideally all python)? I’m all ears on better approaches.