[IPython-User] using iPython as a way to generate repetitive reports.
Sun Dec 2 12:00:25 CST 2012
Le 2 déc. 2012 à 00:17, Zachary Charlop-Powers a écrit :
> I recently posted a question to Stack Overflow about the possibility of using iPython to generate reproducible, repetitive reports. (http://stackoverflow.com/questions/13614783/programatically-add-cells-to-an-ipython-notebook-for-report-generation) Lets say that I have a number of Pandas data frames and for each data frame I want to generate a series of tables , graphs and text, and then combine these into a report. I could use a templating system like Jinja but I am curious to know if I could use the iPython framework of ipython-notebook ---> nbconverter ---> pdf/html/etc for the purpose of generating all of the data analyses and the report into a single document. I have followed Thomas K.'s suggestion to use the get_ipython().set_next_input() function to add text to the next code block. For my idea to work, a few things would need to work:
> example code.
> from IPython.core.display import Image, display_png
> x = Image(filename='test.png')
> for i in range(3):
> x = Image(filename='/Users/zachpowers/Downloads/pics/Sieve_1.png')
> get_ipython().set_next_input('Thats What I am Talking About!')
> if you run this you will see that there are a few different problems that you encounter.
> 1) you can't create Markdown cells
We want to keep kernel separate from fronted, so we'll keep it as less aware as the frontend as possible. So adding MD cell to a kernel method is unlikely.
> 2) the display_png() function does not respect the .set_next_input() function so they are all displayed in the same output block in which they are called
Display_png does not 'return' a value to be displayed, it send the png to the display channel.
So it is normal that it does not put the png in the next cell.
Btw it is set next **input** so by definition is does only works on input so only with text.
> 3) the .set_next_input() function would need to be modified to track which code blocks it insert. It iterates over the loop and inserts a code block below the code block it sits in with the result that the code blocks are added in reverse order from expected.
same as 1.
> 4) there would need to be a way to hide the code-block that calls the rest of the functions.
> 5) you would probably still need a templating engine to generate interesting text of each markdown block
> So in closing I think the python ---> nbconvert is a great tool and that it might potentially be useful for reproducible research of repetitive reports (say that five times fast). I think that a few tweaks to the ipython notebook might make this possible and that the benefit would be the creation of a single file from which analyses could be rerun and from which reports could be generated. However, upon writing up my thoughts I am not sure that this is easier than doing the analysis in one file and outputting the results via a separate templating system.
IIUC, you are seeing this the wrong way.
You can generate .ipynb file without ever going through the browser.
Trying to "pilot" the browser to do that is overcomplicated.
ipynb files are "simple" Json files you can manipulate/create as you wish.
What you want is a headless program that taking a template .ipynb files and somme command modify it.
See some example here :
of gist modifying ipynb structure, or ever re-running ipynb files in a headless manner.
What do you think ?
> I hope some of the iPython community might find this line of thought to be useful and if so we could try to implement some of these ideas.
> zach cp
> IPython-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User