1

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?

Community
  • 1
  • 1
Allosteric
  • 871
  • 1
  • 9
  • 14
  • the question you linked seems exactly same to me, am I missing something? Also if you are going to output 'the chosen number was ...' you probably should just print it. It could be confusing with non int types. edit: Nevermind I didn't read other question correctly... – umutto Mar 07 '17 at 09:00
  • In the link the output will be marked down. instead I would like the markdown itself to include the output. in this way it can obliterate the In[1]: kind of part which makes it easy to read and I can write other markdown in a markdown cell. – Allosteric Mar 07 '17 at 09:01

1 Answers1

2

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

Louise Davies
  • 14,781
  • 6
  • 38
  • 41
  • Is this supported in Jupyter lab? – BND Mar 23 '19 at 15:39
  • 1
    @BND From https://github.com/ipython-contrib/jupyter_contrib_nbextensions#jupyterlab, it seems as though JupyerLab does not currently support `nbextensions`. I believe it's in the roadmap for JupyterLab to eventually port `nbextensions`, but for now you should either use the original notebook or follow the Python rendered Markdown example in this issue: https://github.com/ipython-contrib/jupyter_contrib_nbextensions/issues/1360 – Louise Davies Mar 25 '19 at 14:46