royk
royk

Reputation: 95

Can ipywidgets access the notebook save/load functionality?

In Jupiter lab, can I have an ipywidgets "Save" and "Load" buttons which call the save/load of the notebook?

And can I access the is_saved attribute of the notebook?

Much thanks!

Upvotes: 1

Views: 161

Answers (1)

Sergio Gao
Sergio Gao

Reputation: 429

Yes, just use the ipywidget button with the module ipylab. This module make a connection with the jupyterlab's backend/frontend.

from ipylab import JupyterFrontEnd
from ipywidgets import widgets

def save_button_func(button):
    app = JupyterFrontEnd()
    app.commands.execute('docmanager:save')

save_button = widgets.Button()
save_button.description = 'Save this notebook'
save_button.on_click(save_button_func)
save_button

to load notebook is the same logic, you can find the code with element inspect on the browser or search in git project.

Upvotes: 1

Related Questions