Render all markdown cells in a Jupyter notebook at once - jupyter-notebook

Is there a convenient way to render all markdown cells in a Jupyter notebook at once without running the code cells?
I find it quite annoying that while moving through my notebook and doing some little corrections the markdown cells "loose" their formatting. Is there an extension or a command with which I can "run" (i.e. render) all and only the markdown cells? If not, is there a way to at least update the table of content from the markdown cells. My table of content is realized via nbextensions.

You could use JupyterLab which provides a Render all Markdown cells action if you are not limited to plain Jupyter notebooks. Doing this programmatically within the notebook seems to be not trivial to do as we can derive from this GitHub issue. We might be able to implement this ourselves, but I am not aware of any resources that provide something similar.

Related

Export certain jupyter notebook cells to python file

I'm looking for a library/tool that can generate a .py file from a notebook, with the added feature that I want to control which cells (both code and markdown cells) get exported and/or excluded from the .py file. For example adding to cells something like %exclude or %include and have control at export time how to work with these tags. I found jupytext that may do this, but got me confused with the version control part / link of .ipynb/.md.

Can Visual Studio Code provide live previews of R Notebooks?

I use Visual Studio Code for everything aside from generating reports with R Markdown. For that, I still use RStudio. When I am trying out some new code and exploring data, I usually use an R Notebook file. The killer feature for me is being able to preview it: I can add some text and some code and see how it will look like in the HTML file without having to knit it all over. My understanding is that, as of 2021, that is main difference between R notebooks and "plain" R Markdown files.
I prefer VS Code over RStudio any day but I miss that preview feature. Every time I need to see how simple modifications I did on the .Rmd file look on the HTML file, I have to knit it. Currently, I am using Yuke Ueda's R extension for VS Code: https://marketplace.visualstudio.com/items?itemName=Ikuyadeu.r
My question for the community is: is there a way to enable the same preview capabilities of RStudio on VS Code? Essentially, I would like to see changes I did on the .Rmd file be reflected on the .nb.html file as soon as I save the .Rmd, as in RStudio. Thanks!

rmarkdown running child chunks from inside RStudio

I've been moving some of the code for a report I'm writing to child .rmd files. I want to run these chunks by clicking on the green arrow (top right):
But this doesn't work in RStudio, is this a feature or a bug?
This has not been implemented in RStudio yet, and probably won't be for some time.
However, you can write your R code in a separate file, reference it in R Markdown chunks, and execute those chunks interactively in RStudio. The way to do this is with knitr's code externalization feature. You can read about how to use it in R Markdown notebooks here:
https://rmarkdown.rstudio.com/r_notebooks.html#executing_code (scroll down a bit to Executing External Chunks)
More on code externalization with knitr here:
https://yihui.name/knitr/demo/externalization/

Using Output In markdown Jupyter notebook

I am using Jupyter Notebook to write my report and it would be convenient to include an output in my markdown.
The question below is a simillar question.
Jupyter notebook output in markdown
For example, I have a code cell with the code
In[1]: import random
a = random.randint(1,4);a
and the output was
Out[1]: 2
in my report, I would realy like to include this output just like
'the chosen number was 2'
however, as the 2 is a random number, it would be very convenient to have a way to include the variation a in my markdown like;
'the chosen number was %a'
kind of way.
Is there any way to achieve this?
It's not possible in the main notebook yet (although there are discussions about it) but there is an extension which should suit your purposes:
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/python-markdown/readme.html
It's contained within the ipython-contrib-extensions package, for which the install instructions are here:
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html

Inserting a Link to a Webpage in an IPython Notebook

How is this done? I'd like to have the link be in a markdown cell.
For visual learners:
[blue_text](url_here)
In case it is not a markdown cell, that is with what I went:
from IPython.core.display import display, HTML
display(HTML("""text"""))
Just another tip, using magic expression.
%%html
Showing Text
Improved. Thanks to the comment of calocedrus.
Here is the code I use in my python notebook when I want to insert a link to a webpage inside a markdown cell (in a python notebook).
[Clickable_visible_hyperlink](Hidden_landing_URL)
--note Here is the clickable hyperlink, you can change the value
This might help too, if you're looking to display a link programmatically.
from IPython.display import display, Markdown
display(Markdown("[google](https://www.google.com)"))
I also tried
display(HTML("""<a href="https://www.google.com>google</a>"""))
But somehow I was getting the object printed out, instead of the rendered version.
For programming in R, do the following when using Jupyter Notebook or Jupyter Lab - (using the R kernel). These steps will display a web link and an image in a Notebook markdown cell. The following shows a real-life example of some study notes using Jupyter Lab and R.
First open a markdown cell in Jupyter - can be a new markdown cell or an existing markdown cell. Then copy and paste the actual web address into a markdown cell. This will provide an active link to that website from the Notebook.
Step 2, from that website, copy the image that you want to view in the Notebook. This image should be in a standard image format (.png, .jpg, etc ). Paste this image into the same folder on the computer where the Jupyter notebook file is located. Note: if the image is later deemed too large or small, then resize using any graphics software available - and then save the changed image into this same folder. Note: it is important to know the name of this image file.
Next, paste the name of the image file between the quotation marks in the following code: . If this file in not within your existing jupyter notebook working directory, then a path to the image file will need to be placed inside the quotation marks.
Step 3, also included is an example of the line of code (also used in Notebook markdown cell) to create colored text in markdown cells. In this line of code, the double ## character results in the second largest font being used in Jupyter. Smaller text using more of these characters - with #### being the smallest. One # results in the largest font output.
Last, be sure to close and run the markdown cell to view the output. The code for the markdown cell follows, and further below shows the output from the Notebook.
Code in Markdown cell:
"https://www.tensorflow.org/images/colab_logo_32px.png" # link to website
<img src="tidyflow.png" /> # The image file (This path is the same folder as Notebook file)
## <font color = cyan> Some Colored Text in Notebook Markdown Cell </font> # colored text
Output:

Resources