Search code examples
pythonjupyter-notebookjupyterpython-markdown

Evaluate a cell once another cell has finished


I use Python Markdown extension so that I can visualize the results nicely (I create an URL from the results). Is there a way to make the cell with the markdown that uses this {{x}} notation dependent on a cell where x was introduced or changed? Because it's not obvious that user should evaluate a cell with markdown.

better visualization:

cell1 (python): 
------------------------------
x=1
url="http://example.com/" + x
------------------------------


cell2 (markdown): 
------------------------------
foo is available on {{url}}
------------------------------

And I want the cell2 to be run when cell1 is run.


Solution

  • This could be accomplished by in single cell by using IPython's builtin Markdown function to format the output:

    from IPython.display import Markdown
    
    x=1
    url="http://example.com/" + str(x)
    
    Markdown('foo is avalible on '+url)