Debian Codegraph @

examples/knitpy_overview.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <meta http-equiv="Content-Style-Type" content="text/css" />
6 <meta name="generator" content="pandoc" />
7 <meta name="author" content="Jan Schulz" />
8 <title>knitpy: dynamic report generation with python</title>
9 <style type="text/css">code{white-space: pre;}</style>
10 <style type="text/css">
11 table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
12 margin: 0; padding: 0; vertical-align: baseline; border: none; }
13 table.sourceCode { width: 100%; line-height: 100%; }
14 td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
15 td.sourceCode { padding-left: 5px; }
16 code > span.kw { color: #007020; font-weight: bold; }
17 code > span.dt { color: #902000; }
18 code > span.dv { color: #40a070; }
19 code > span.bn { color: #40a070; }
20 code > span.fl { color: #40a070; }
21 code > span.ch { color: #4070a0; }
22 code > span.st { color: #4070a0; }
23 code > span.co { color: #60a0b0; font-style: italic; }
24 code > span.ot { color: #007020; }
25 code > span.al { color: #ff0000; font-weight: bold; }
26 code > span.fu { color: #06287e; }
27 code > span.er { color: #ff0000; font-weight: bold; }
28 </style>
29 </head>
30 <body>
31 <div id="header">
32 <h1 class="title">knitpy: dynamic report generation with python</h1>
33 <h2 class="author">Jan Schulz</h2>
34 <h3 class="date">12.03.2015</h3>
35 </div>
36 <p>This is a port of knitr (<a href="http://yihui.name/knitr/" class="uri">http://yihui.name/knitr/</a>) and rmarkdown (<a href="http://rmarkdown.rstudio.com/" class="uri">http://rmarkdown.rstudio.com/</a>) to python.</p>
37 <p>For a complete description of the code format see <a href="http://rmarkdown.rstudio.com/" class="uri">http://rmarkdown.rstudio.com/</a> and replace <code>{r...}</code> by <code>{python ...}</code> and of course use python code blocks…</p>
38 <div id="examples" class="section level2">
39 <h2>Examples</h2>
40 <p>Here are some examples:</p>
41 <pre class="sourceCode python"><code class="sourceCode python"><span class="dt">print</span>(<span class="st">&quot;Execute some code chunk and show the result&quot;</span>)</code></pre>
42 <pre><code>## Execute some code chunk and show the result</code></pre>
43 <p>Codechunks which contain lines without output (e.g. assign the result or comments) will be shown in the same code block:</p>
44 <pre class="sourceCode python"><code class="sourceCode python"><span class="co"># A comment</span>
45 text = <span class="st">&quot;All code in the same code block until some output is produced...&quot;</span>
46 more_text = <span class="st">&quot;...and some more.&quot;</span>
47 <span class="dt">print</span>(text)</code></pre>
48 <pre><code>## All code in the same code block until some output is produced...</code></pre>
49 <pre class="sourceCode python"><code class="sourceCode python"><span class="dt">print</span>(more_text)</code></pre>
50 <pre><code>## ...and some more.</code></pre>
51 <div id="code-chunk-arguments" class="section level3">
52 <h3>Code chunk arguments</h3>
53 <p>You can use different arguments in the codechunk declaration. Using <code>echo=False</code> will not show the code but only the result.</p>
54 <pre><code>## Only the output will be visible as `echo=False`</code></pre>
55 <p>The next paragraphs explores the code chunk argument <code>results</code>.</p>
56 <p>If ‘hide’, knitpy will not display the code’s results in the final document. If ‘hold’, knitpy will delay displaying all output pieces until the end of the chunk. If ‘asis’, knitpy will pass through results without reformatting them (useful if results return raw HTML, etc.)</p>
57 <p><code>results='hold'</code> is not yet implemented.</p>
58 <pre class="sourceCode python"><code class="sourceCode python"><span class="dt">print</span>(<span class="st">&quot;Only the input is displayed, not the output&quot;</span>)</code></pre>
59 <pre><code>## This is formatted as markdown:
60 ## **This text** will be bold...</code></pre>
61 <p><strong>This text</strong> will be bold…</p>
62 <p><strong>Note</strong>: with python code it is recommended to use the IPython/Jupyter display system and an appropriate wrapper (see below) to display such output and not <code>results=&quot;asis&quot;</code>. This makes it possible to convert such output if the output can’t be included in the final format.</p>
63 <p>You can also not show codeblocks at all, but they will be run (not included codeblock sets <code>have_run = True</code>):</p>
64 <pre class="sourceCode python"><code class="sourceCode python"><span class="kw">if</span> have_run == <span class="ot">True</span>:
65 <span class="dt">print</span>(<span class="st">&quot;'have_run==True': ran the codeblock before this one.&quot;</span>)</code></pre>
66 <pre><code>## 'have_run==True': ran the codeblock before this one.</code></pre>
67 <p>Using <code>eval=False</code>, one can prevent the evaluation of the codechunk</p>
68 <pre class="sourceCode python"><code class="sourceCode python">x = <span class="dv">1</span></code></pre>
69 <pre class="sourceCode python"><code class="sourceCode python">x += <span class="dv">1</span> <span class="co"># this is not executed as eval is False</span></code></pre>
70 <pre class="sourceCode python"><code class="sourceCode python">x <span class="co"># still 1</span></code></pre>
71 <pre><code>## 1</code></pre>
72 <p>To remove/hide a codechunk completely, i.e. neither execute it nor show the code, you can use both <code>eval=False, include=False</code>: nothing will be shown between this text …</p>
73 <pre class="sourceCode python"><code class="sourceCode python">x += <span class="dv">1</span> <span class="co"># this is not executed and not even shown</span></code></pre>
74 <p>… and this text here!</p>
75 <p>The prefix in front of text output (per default <code>##</code>) can be changed via the <code>comment</code> chunk option to a different string or completely removed by setting it to a empty string <code>&quot;&quot;</code>or None:</p>
76 <pre class="sourceCode python"><code class="sourceCode python"><span class="dt">print</span>(<span class="st">&quot;Text output&quot;</span>)</code></pre>
77 <pre><code># result: Text output</code></pre>
78 <pre class="sourceCode python"><code class="sourceCode python"><span class="dt">print</span>(<span class="st">&quot;Text output&quot;</span>)</code></pre>
79 <pre><code>Text output</code></pre>
80 </div>
81 <div id="inline-code" class="section level3">
82 <h3>Inline code</h3>
83 <p>You can also include code inline: “m=2” (expected: “m=2”)</p>
84 </div>
85 <div id="ipython-jupyter-display-framework" class="section level3">
86 <h3>IPython / Jupyter display framework</h3>
87 <p>The display framework is also supported.</p>
88 <p>Plots will be included as images and included in the document. The filename of the plot is derived from the chunk label (“sinus” in this case). The code is not shown in this case (<code>echo=False</code>).</p>
89 <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX0AAAEACAYAAABfxaZOAAAABHNCSVQICAg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c4HLgCuJTiVLmyD6AAiGJXTp9TutmLvqQFKA7C/n1EXJg7T1/Sj/eXAOvlztKNDwNbS3oQOAP4mKRTM2fqVkT8M/3+JMX8cxnn9R8FHo2I2QfKnEvxTaCsPgX8Pf2dls16wLUR8VTayn0+xb/X0omICRGxXkRsBjwL3Js7Uy9mSloGQNKy0Pepc7l37wg4GbgrIo7MmaU3kpaevSouaSHgExQjgFKJiB9ExLCIWInix/w/RcRXcueam6SFJS2W3l4E2IKia2upRMQTwAxJs4+Q3By4M2Okvoyh+GZfRvcAG0laKH3dbw7lPCVN0nvS7ytQdBIu3XRZFxcBO6e3dwb6HDjnPjlrY4pmXLdJml1E94uIlp7YNAjLAqdIehvFN8rTIuKqzJn6o6y7d4YAFxRf+8wPnB4RV+SN1KN9gNPT1MkDwLjMebqVvnluTrFDpnQiYlr6qfMmiumSm4ET8qbq0bmSlqJYeN4rIv6TOxCApDOAzYCl04OxB1C0KT9b0q7AQ8B2fb6OH84yM6uP7HP6ZmbWPi76ZmY14qJvZlYjLvpmZjXiom9mViMu+mZmNeKib2ZWIy76ZmY18v8/UUmPi8V8AgAAAABJRU5ErkJggg==" /></p>
90 <p>If a html or similar thing is displayed via the IPython display framework, it will be included ‘as is’, meaning that apart from <code>text/plain</code>-only output, everything else will be included without marking it up as output. Knitpy automagically tries to include only formats which are understood by pandoc and the final output format (in some case converting the format to one which the final output can handle).</p>
91 <pre class="sourceCode python"><code class="sourceCode python"><span class="ch">from</span> IPython.core.display <span class="ch">import</span> display, HTML
92 display(HTML(<span class="st">&quot;&lt;strong&gt;strong text&lt;/strong&gt;&quot;</span>))</code></pre>
93 <p><strong>strong text</strong></p>
94 <p>It even handles <code>pandas.DataFrames</code> (be aware that not all formatting can be converted into all output formats):</p>
95 <pre class="sourceCode python"><code class="sourceCode python"><span class="ch">import</span> pandas <span class="ch">as</span> pd
96 pd.set_option(<span class="st">&quot;display.width&quot;</span>, <span class="dv">200</span>)
97 s = <span class="st">&quot;&quot;&quot;This is longer text&quot;&quot;&quot;</span>
98 df = pd.DataFrame({<span class="st">&quot;a&quot;</span>:[<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">5</span>],<span class="st">&quot;b&quot;</span>:[s,<span class="st">&quot;b&quot;</span>,<span class="st">&quot;c&quot;</span>,s,<span class="st">&quot;e&quot;</span>]})
99 df</code></pre>
100 <div style="max-height:1000px;max-width:1500px;overflow:auto;">
101 <table border="1" class="dataframe">
102 <thead>
103 <tr style="text-align: right;">
104 <th>
105 </th>
106 <th>
107 a
108 </th>
109 <th>
110 b
111 </th>
112 </tr>
113 </thead>
114 <tbody>
115 <tr>
116 <th>
117 0
118 </th>
119 <td>
120 1
121 </td>
122 <td>
123 This is longer text
124 </td>
125 </tr>
126 <tr>
127 <th>
128 1
129 </th>
130 <td>
131 2
132 </td>
133 <td>
134 b
135 </td>
136 </tr>
137 <tr>
138 <th>
139 2
140 </th>
141 <td>
142 3
143 </td>
144 <td>
145 c
146 </td>
147 </tr>
148 <tr>
149 <th>
150 3
151 </th>
152 <td>
153 4
154 </td>
155 <td>
156 This is longer text
157 </td>
158 </tr>
159 <tr>
160 <th>
161 4
162 </th>
163 <td>
164 5
165 </td>
166 <td>
167 e
168 </td>
169 </tr>
170 </tbody>
171 </table>
172 </div>
173 <p><code>pandas.DataFrame</code> can be represented as <code>text/plain</code> or <code>text/html</code>, but will default to the html version. To force plain text, use either <code>print(df)</code> or set the right <code>pandas</code> option:</p>
174 <pre class="sourceCode python"><code class="sourceCode python">pd.set_option(<span class="st">&quot;display.notebook_repr_html&quot;</span>, <span class="ot">False</span>)
175 df</code></pre>
176 <pre><code>## a b
177 ## 0 1 This is longer text
178 ## 1 2 b
179 ## 2 3 c
180 ## 3 4 This is longer text
181 ## 4 5 e</code></pre>
182 <pre class="sourceCode python"><code class="sourceCode python"><span class="co"># set back the display</span>
183 pd.set_option(<span class="st">&quot;display.notebook_repr_html&quot;</span>, <span class="ot">True</span>)</code></pre>
184 <p>You can also use package like <a href="https://bitbucket.org/astanin/python-tabulate">tabulate</a> together with <code>results=&quot;asis&quot;</code> or by wrapping it with the appropriate display class:</p>
185 <pre class="sourceCode python"><code class="sourceCode python"><span class="ch">from</span> tabulate <span class="ch">import</span> tabulate
186 <span class="ch">from</span> IPython.core.display <span class="ch">import</span> Markdown
187 <span class="co"># either print and use `results=&quot;asis&quot;`</span>
188 <span class="dt">print</span>(tabulate(df, <span class="dt">list</span>(df.columns), tablefmt=<span class="st">&quot;simple&quot;</span>))</code></pre>
189 <table>
190 <thead>
191 <tr class="header">
192 <th align="left"></th>
193 <th align="left">a</th>
194 <th align="left">b</th>
195 </tr>
196 </thead>
197 <tbody>
198 <tr class="odd">
199 <td align="left">0</td>
200 <td align="left">1</td>
201 <td align="left">This is longer text</td>
202 </tr>
203 <tr class="even">
204 <td align="left">1</td>
205 <td align="left">2</td>
206 <td align="left">b</td>
207 </tr>
208 <tr class="odd">
209 <td align="left">2</td>
210 <td align="left">3</td>
211 <td align="left">c</td>
212 </tr>
213 <tr class="even">
214 <td align="left">3</td>
215 <td align="left">4</td>
216 <td align="left">This is longer text</td>
217 </tr>
218 <tr class="odd">
219 <td align="left">4</td>
220 <td align="left">5</td>
221 <td align="left">e</td>
222 </tr>
223 </tbody>
224 </table>
225 <pre class="sourceCode python"><code class="sourceCode python"><span class="co"># or use the IPython display framework to publish markdown</span>
226 Markdown(tabulate(df, <span class="dt">list</span>(df.columns), tablefmt=<span class="st">&quot;simple&quot;</span>))</code></pre>
227 <table>
228 <thead>
229 <tr class="header">
230 <th align="left"></th>
231 <th align="left">a</th>
232 <th align="left">b</th>
233 </tr>
234 </thead>
235 <tbody>
236 <tr class="odd">
237 <td align="left">0</td>
238 <td align="left">1</td>
239 <td align="left">This is longer text</td>
240 </tr>
241 <tr class="even">
242 <td align="left">1</td>
243 <td align="left">2</td>
244 <td align="left">b</td>
245 </tr>
246 <tr class="odd">
247 <td align="left">2</td>
248 <td align="left">3</td>
249 <td align="left">c</td>
250 </tr>
251 <tr class="even">
252 <td align="left">3</td>
253 <td align="left">4</td>
254 <td align="left">This is longer text</td>
255 </tr>
256 <tr class="odd">
257 <td align="left">4</td>
258 <td align="left">5</td>
259 <td align="left">e</td>
260 </tr>
261 </tbody>
262 </table>
263 <p>Note that the second version (wrapping it in <code>Markdown</code>) is preferred, as this marks the output with the right mimetype and therefore can be converted—if that’s needed—to something which the output format understands!</p>
264 <p>Unfortunately, html tables have to be tweaked for the final output format as e.g. too width tables spill over the page margin in PDF.</p>
265 </div>
266 <div id="error-handling" class="section level3">
267 <h3>Error handling</h3>
268 <p>Errors in code are shown with a bold error text:</p>
269 <pre class="sourceCode python"><code class="sourceCode python"><span class="ch">import</span> sys
270 <span class="dt">print</span>(sys.not_available)</code></pre>
271 <p><strong>ERROR</strong>: AttributeError: ‘module’ object has no attribute ‘not_available’</p>
272 <pre><code>AttributeError Traceback (most recent call last)
273 &lt;ipython-input-37-a5971246c0f7&gt; in &lt;module&gt;()
274 ----&gt; 1 print(sys.not_available)
275
276 AttributeError: 'module' object has no attribute 'not_available'</code></pre>
277 <pre class="sourceCode python"><code class="sourceCode python"><span class="kw">for</span> x in []:
278 <span class="dt">print</span>(<span class="st">&quot;No indention...&quot;</span>)</code></pre>
279 <p><strong>ERROR</strong>: Code invalid</p>
280 </div>
281 </div>
282 </body>
283 </html>