jtpio / ipylab

Control JupyterLab from Python Notebooks with Jupyter Widgets 🧪 ☢️ 🐍
BSD 3-Clause "New" or "Revised" License
199 stars 13 forks source link

Convert notebook with ipylab #102

Open simbalsyd opened 2 years ago

simbalsyd commented 2 years ago

Hi,

Usually I am using nbconvert to convert a notebook to html. Today I was searching for a way to do it via code from inside the notebook. When searching for it I found ipylab and the command "notebook:export-to-format" but I don't understand how to use it.

From the notebook I did

from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
app.commands.execute("docmanager:save")
app.commands.execute("notebook:export-to-format")

I get no error messages but also no file.

What I eventually would like to do is something corresponding to nbconvert --to html --template classic --no-input notebook

Do you have any idea on how to do it?

jtpio commented 2 years ago

Thanks @simbalsyd.

It should be possible to use the following to export the current notebook to HTML:

app.commands.execute('notebook:export-to-format', {
    'format': 'html',
})

https://user-images.githubusercontent.com/591645/187077772-8f28a449-cc1d-4640-97fa-8f5a58c3c769.mp4

Not sure it would support setting the template or --no-input flag. Or maybe by combining it with https://github.com/timkpaine/jupyterlab_commands.

anstiwar commented 1 year ago

Thanks a lot @jtpio, this helped me a lot.

Can you also provide an example to provide the location where we can export the file (If it's possible)