Jupyterlab extension to add a button to save the notebook and launch a command

To produce a static presentation from a notebook pres.ipynb, I run a command like

jupyter-nbconvert pres.ipynb \
    --to slides --no-input --SlidesExporter.reveal_scroll=True \
    --SlidesExporter.reveal_number=c/t \
  && sed -i 's$<meta charset="utf-8" />$<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />$g' pres.slides.html

In practice, I do that with a Makefile. First, I need to save the notebook in Jupyterlab and then, switch to a terminal and run make.

This process is quite inconvenient and it would be great to have a button to save the notebook and run a particular command (better if it can be saved in the notebook) to do something with the notebook.

I didn’t find an extension to do that. Does something like that already exist? If not, would it be not too difficult to develop such extension?

It looks like this can be done by developing an extension. There is an example of adding a button to the Toolbar in the tutorial; when the button is pressed you could send a request to the server side part of the extension, which would execute the command.

1 Like

Thanks for the reply.

For the record, the example on how to add a button in the notebook toolbar is here

To write this extension, I would need to implement the function called when the new button is clicked. The steps are

  • save the notebook
  • read the metadata of the notebook where should be written (by the user) the command to be executed (with nice logging if the command is not found)
  • execute the command on the server (with nice logging on error)

It seems doable but it’s not evident to me how to do that (especially because I don’t know JS/TypeScript). I’m going to look into the examples and documentations but some hints would be very appreciated :slight_smile: