I'm used to hitting the R key in jupyter to change it to raw NbConvert type which deactivates it, but I don't see that option in the shortcuts for vscode. Is there a way to change a cell to raw nbconvert in vscode, or some equivalent way of preventing a cell from accidentally being run? raw format is perfect because it's easy to tell
apparently (from what I know) there's no shortcut key to change a cell to raw. However it's possible to change a cell to raw NbConvert from the GUI.
From the picture above, you can see that this Python/raw is shown at the bottom right of a cell. Just simply click on the Python word and choose raw from the pop out selection and boom. You get a raw NbConvert cell. Hope this helps! :)
Related
Below is a screenshot of what I mean. I'd like it to show only the headers of the notebook, not each and every single markdown block. Is there a similar way to changing this, like in JupyterLab, where you can toggle different outline options?
We can format python code in the jupyter notebook in the browser. After I change to VSCode and use the Microsoft extension, I find I can not format Jupyter notebook any more. Does anyone know how to solve this?
As Kyle Carow stated in their answer to Ian Huff: Formatting of notebooks is available by now.
MacOS: Option+Shift+F
Windows: Alt+Shift+F
Pressing these keys will either trigger a formatting of the active cell or the notebook as a whole if no cell is active.
Windows: Shift+Alt+F
Is what worked for me with Black formatter set up on VS Code Version: 1.64.2
Or right click "Format Notebook" to format entire notebook.
Format Notebook
I do not think VS Code support formatting of code cells, but if you use the black code formatter, then you can use the blackcellmagic %%black to format the code in a cell.
You need to have pip install black and blackcellmagic, details here: https://github.com/csurfer/blackcellmagic
I'm not exactly sure what is being asked here. But currently in VS Code the notebook editor and interactive window do not support formatting python code.
However we are moving to a new UI for those features which will support all the formatting features of VS Code in .py files. If you try out VS Code - Insiders now you should see this support and can try it out. This new UI will eventually be rolling out to VS Code stable.
Edit: The new UI which supports formatting in cells is now out by default for stable users.
If you have a Jupyter notebook open in VS Code with the Jupyter notebook extension, it should be possible to format code cells with Ctrl+ Shift+ I.
I'm not sure if this shortcut differs between operating systems, you can check what the shortcut is yourself by hitting Ctrl+ Shift+ P and then searching for "Format cell". The shortcut should be displayed then.
I have issues on jupyter notebook conversion. It looks fine on jupyter notebook. However if I convert it to html or upload to github, it displays like photo above.
Instead of vertical(scroll up and down), I have to scroll left and right and each cell are really narrowed.
Any suggestion?
Thanks in advance!
This is typical of a library you use emitting invalid HTML. I would suggest opening an issue or contacting the Jupyter mailing list to help you debug this as StackOverflow will not be the right place to have a back and forth.
You should be able to narrow down which library does that by:
- backup your notebook.
- Delete cells one and until notebook looks normal. (tip use nbconvert locally instead of uploading, and use python -m http.server)
- the last cell you delete have a issue.
It may be a bug in nbconvert but I doubt it.
I'm working on a jupyter notebook (from a local installation of jupyterhub) that I want to be able to copy and distribute to my coworkers. Some of them are a little 'code-phobic' so I want to be able to portions of the code from them.
I can use the hide input extension to very prettily hide the code in my own notebook, however when I make a copy the cell meta-data for hide input reverts to "hide_input": false, and the code is all automatically visible.
Is there a way to keep cell meta data in the copying process?
I can find a lot of online discussions/documentation about keeping hide input functionality with nbconvert, however I don't want to convert to html because I still need the users to be able to actually run code.
Is there a way to use nbconvert to make a copy of a notebook and not actually convert it?
Thanks.
I'm confused - because for me cell metadata is preserved when copied. Are you sure you are actually saving the notebook after you have changed the cell metadata?
Regardless, you can use nbconvert to "convert" a notebook into a notebook; use the command:
jupyter nbconvert --to notebook --execute mynotebook.ipynb
From the docs: https://nbconvert.readthedocs.io/en/latest/usage.html#notebook-and-preprocessors
If you use the Toggle selected cell input button or individually edit cell metadata the individual cell hide input status was not preserved. But when I used the Hide codecell inputs to hide the input of all the cells; then it was preserved after copying.
In this tutorial presentation they use this, but, apparently, they don't show you how to do it.
http://www.damian.oquanta.info/posts/make-your-slides-with-ipython.html
Thanks,
I am sorry, I completely misunderstood your question.
If you mean embedding code which you do not execute, then you can use simple markdown syntax (similar to StackOverflow for example). To include inline code, just but it between backticks:
For example `a[::2]` selects every second element of the list `a`.
If you want to include a code block, either indent the whole block by 4 spaces, or put the block between 3 backticks (the latter also supports syntax highlighting if you specify the language):
a = foo()
b = bar(a)
or
```python
a = foo()
b = foo(a)
```
For more, see this markdown tutorial.
If you want to include executable cells and markdown on the same slide, then you need to put your code and markdown into different cells, and for slide type select slide for the topmost cell, and - for the subsequent cells that you want to have on the same slide. - means "do not start a new slide for this cell".
Old answer (how to convert a notebook to a reveal.js presentation)
You can convert your ipython notebook to a Reveal.js presentation using nbconvert.
First you have to specify the structure of the presentation. For that click on View -> Cell Toolbar -> Slideshow. Then at the top of every cell you can select whether you want it to be a new slide (horizontal direction), a subslide (vertical direction), a fragment (appear on the same slide with a fade-in) and some others.
Once you are set, you can use the nbconvert utility to transform your notebook into a presentation. The basic usage is
jupyter nbconvert example.ipynb --to slides
Then you get a HTML which you can serve up later using some web server.
If you want to show off your slides right away, jupyter provides a shortcut: you can do
jupyter nbconvert example.ipynb --to slides --post serve
Using this jupyter starts a local server after the conversion and opens the presentation in your default browser.
Last, if you want to easily share your presentation online, you can upload the notebook to some online repository (for example to github as a gist), and you can use nbviewer to share it. It will have a box-like icon in the top right corner. If you press it, it will change from notebook mode to presentation mode (I don't understand the box analogy either).
For more info please consult the jupyter documentation.