如何在Jupyter笔记本中编程添加幻灯片元数据?
jupyter笔记本电脑具有可视化单元格元数据的一种方式,因此当您使用nbconvert
将笔记本电脑导出到幻灯片中时,可以参数化单元格的外观。
例如,我想在不使用GUI的情况下编程地将该元数据添加到单元中元数据工具。
我遇到此
参考/Jupyterbook.org/en/stable/content/metadata.html#add-tags-using-python-code
哪个可以编程地添加元数据以隐藏单元格代码。我希望能够做同样的事情,但是添加幻灯片元数据。例如,我不确定我应该遵循什么{tags:values}
或语法。
Jupyter notebooks has a way of visualizing cell metadata so that you are able to parametrize how will cells look like when you export the notebook into slides using nbconvert
.
For instance, I would like to programmatically add that metadata into cells without using the GUI, so that I can automate slide creation, specially from google colaboratory as it doesn't support the Edit Cell Metadata tool.
I've come across this reference
https://jupyterbook.org/en/stable/content/metadata.html#add-tags-using-python-code
which programmatically adds metadata to hide cell code. I would like to be able to do the same but adding slideshow metadata. For instance I am not sure what {tags:values}
or syntax I should follow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 nbformat 像您指向的示例一样执行此操作。
nbformat作为jupyter的一部分,因此在运行笔记本电脑的任何地方都可以运行。
我使用nbformat来执行与您的目标相似的事情在这里(在work-In-In-in-in-in-progress状态下)。最相关的部分是
就您而言,听起来您已经在笔记本中拥有内容,因此,在您的情况下,您需要在笔记本上阅读,就像先这样的书籍:
然后像我的示例一样修复元数据。沿着这些线路:
您可以尝试我设置的自动化,启动幻灯片构建过程,并通过那里,然后单击
启动活页夹
。我认为,如果您只是在笔记本上运行内容,它将指导您通过每张幻灯片上的一些矩形并排制作幻灯片,作为图像的替身。您还会看到我在,基于整个笔记本的元数据玩幻灯片自动打开笔记本时,即
“ livereVeal”:{“ autoLaunch”:true,“ scroll”:true}
e节。nbconvert includes a preprocessor that will edit metadata, see here< /a>看起来会添加元数据。
如果您使用JupyterLab作为幻灯片开发工具,则可以安装Jupyterlab-Deck,该工具栏将添加一个“甲板”图标,使您可以在SlideCk Viewing中切换和向外切换。请参阅在此处使用。 (在通过Mybinder提供的会话甲板模式下,如果将鼠标移到屏幕顶部,我会看到工具栏。我认为这是因为
shift+Esc
不起作用。 '已更新。)You can use nbformat to do this like the example you point to.
nbformat comes as part as Jupyter so it runs wherever you have your notebooks running.
I use nbformat to do something similar to your goal here (in a work-in-progress state). The most pertinent part is here where I set the meta data for cells in the notebook to be a slide show. Here's the gist of that section:
In your case, it sounds like you already have the content in your notebook, and so in your case you'll want to read in the notebook, like this first:
And then fix the metadata like my example. Something along these lines:
You can try the automated, work-in-progress slide building process I set up and referred to above by going there and clicking
launch binder
. I think if you just run things in the notebook that comes up it will guide you through making slides with some filled rectangles side-by-side on each slide as stand-in for images.You'll also see I use a stub of a notebook in the script, that is based on a notebook stub to add in metadata for the entire notebook here so that it will play the slideshow automatically when the notebook is opened, i.e., the
"livereveal": {"autolaunch": true, "scroll": true}
section.nbconvert includes a preprocessor that will edit metadata, see here where it looks like it will add the metadata.
If you use JupyterLab as your slide development tool, you can install jupyterlab-deck which will add a 'deck' icon to the toolbar that allows you to toggle in and out of the slidedeck viewing. See Usage here. (In deck mode of sessions served via MyBinder, I see the toolbar if I move the mouse towards the top of screen. I assume this is because
shift+esc
doesn't work. Or the documentation just hasn't been updated.)