<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 4, 2014 at 2:18 PM, Alessandro Gagliardi <span dir="ltr"><<a href="mailto:alessandro.gagliardi@glassdoor.com" target="_blank">alessandro.gagliardi@glassdoor.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<div style="word-wrap:break-word;font-size:14px;font-family:Calibri,sans-serif">
<div><font color="#0000ff">I’d like to allow users to generate a CSV in a notebook that is hosted remotely and download that file to their local machine, perhaps through a widget (or some other way that doesn’t require the command line).</font></div>
</div></blockquote><div><br></div><div>Another approach is to use a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs">data URI</a>, where a link is specified "by value" (e.g. the target file contents)  <i>vs</i> "by reference" where the URL points to a server.</div>
<div><br></div><div>For example, this cell presents a link in the output area that downloads a small CSV file:</div><div><br></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra">
<div class="gmail_quote"><div><div><font face="courier new, monospace">%%html</font></div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><font face="courier new, monospace"><a href="data:text/csv,1,2,3,4" target="_blank">Click here to download</a></font></div>
</div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Generalizing, you should be able to get from (say) a Pandas Dataframe to a HTML() IPython display object with a "click to download" link in a few lines of Python.  Or, subclass the dataframe so that all of your dataframe objects offer a "click to download" option.</div>
<div><br></div><div>Pros:</div><div><ul><li>Entirely self-contained, doesn't depend on how/where IPython notebooks are served</li><li>Doesn't require kernel and web server on same machine</li><li>[90% certain] A published notebook (e.g. nbconvert) will work exactly as expected</li>
</ul><div>Cons:</div></div><div><ul><li>Entire CSV content embedded in cell (may be an issue for large files)</li><li>There are corner cases of lacking or partial browser support (notably, old IE)</li><li>The file is always called "download", unless you do Javascript tricks (e.g. see:  <a href="http://stackoverflow.com/questions/833015/does-execcommand-saveas-work-in-firefox/13696029#13696029">http://stackoverflow.com/questions/833015/does-execcommand-saveas-work-in-firefox/13696029#13696029</a>)</li>
</ul><div>Also note there is a new "download" attribute in <a> tags that makes this even easier.  See:  <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a</a>   Unfortunately, the tag is not (yet) in all major browsers.</div>
<div><br></div><div>-andy</div></div><div><br></div></div></div></div>