2016-08-21 4 views
0

私はJupyterノートブックでレポートを作成しています。データの視覚化以外にも、さまざまなテキストの色や書式、脚注などを使って、Google文書からきれいに書式設定されたドキュメントを用意しています。ノートブック全体にドキュメントの一部を散発的に含める必要があります。私は、このようなHTMLをレンダリングしようとする最初の時間は、それが正常に見える、特定のノートブック細胞でレンダリングしたいHTMLとして各部分をダウンロードし、そして今Jupyter Notebook:1つのセルでレンダリングされたHTMLが、別のレンダリングでレンダリングされたHTMLを乱す

IPython.display.HTML(""" [html string] """)

とノートブックに含めるしようとしています。しかし、別のセルにHTMLの2番目の部分をレンダリングしようとすると、は、ランダムな空白とテキストがぼやけて正しくレンダリングされないだけでなく、レンダリングされたHTMLの最初のセル。 1つのセルの出力が別のセルの出力を変更するのはなぜですか?この問題を緩和するために私は何ができますか?私は、完全な書式に第2のセルの出力、最初のリターンの出力をオフにすると、上記ipython.display.HTMLの各コマンドを実行した後

#setup 
import pandas as pd 
import numpy as np 
import math 
import matplotlib.pyplot as plt 
pd.set_option('display.max_columns', 500) 
pd.set_option('display.max_rows', 10000) 
from bokeh.charts.operations import blend 
from bokeh.charts import Bar, Donut, show 
from bokeh.io import output_notebook 
from bokeh.charts.attributes import CatAttr 
from bokeh.models import HoverTool 
import folium 
output_notebook() 
import IPython as ipython 
import IPython.core.display as di 

# This line will hide code by default when the notebook is exported as HTML 
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True) 

ipython.display.HTML("""<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css">ol{margin:0;padding:0}table td,table th{padding:0}.c8{background-color:#ffffff;max-width:468pt;padding:72pt 72pt 72pt 72pt}.c4{font-size:12pt;color:#cc0000;font-weight:700}.c6{orphans:2;widows:2;height:11pt}.c5{line-height:1.0;orphans:2;widows:2}.c10{orphans:2;widows:2}.c0{color:inherit;text-decoration:inherit}.c9{color:#1155cc;text-decoration:underline}.c1{color:#4c515a;font-size:12pt}.c3{width:33%;height:1px}.c7{font-weight:700}.c2{font-size:10pt}.title{padding-top:0pt;color:#000000;font-size:26pt;padding-bottom:3pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.subtitle{padding-top:0pt;color:#666666;font-size:15pt;padding-bottom:16pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}li{color:#000000;font-size:11pt;font-family:"Arial"}p{margin:0;color:#000000;font-size:11pt;font-family:"Arial"}h1{padding-top:20pt;color:#000000;font-size:20pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h2{padding-top:18pt;color:#000000;font-size:16pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h3{padding-top:16pt;color:#434343;font-size:14pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h4{padding-top:14pt;color:#666666;font-size:12pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h5{padding-top:12pt;color:#666666;font-size:11pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h6{padding-top:12pt;color:#666666;font-size:11pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;font-style:italic;orphans:2;widows:2;text-align:left}</style></head><body class="c8"><p class="c10"><span class="c4">SEX AND AGE DISAGGREGATION</span><sup class="c4"><a href="#ftnt1" id="ftnt_ref1">[1]</a></sup></p><p class="c10"><span class="c1">Across the response, the largest age </span><span class="c1">brackets</span><span class="c1">&nbsp;were, understandably </span><span class="c1 c7">18-59 </span><span class="c1">and </span><span class="c1 c7">5-17</span><sup class="c1 c7"><a href="#ftnt2" id="ftnt_ref2">[2]</a></sup><span class="c1">&nbsp;- not surprising, as these are also the widest age </span><span class="c1">brackets</span><span class="c1">. </span></p><p class="c6"><span></span></p><hr class="c3"><div><p class="c5"><a href="#ftnt_ref1" id="ftnt1">[1]</a><span class="c2">&nbsp;</span><span class="c2">Further breakdown of SADD and </span><span class="c2">country of origin</span><span class="c2">&nbsp;data by district/camp within Turkey, Greece or the Balkans is also available. </span><span class="c1">&nbsp;</span></p></div><div><p class="c5"><a href="#ftnt_ref2" id="ftnt2">[2]</a><span class="c2">&nbsp;The range of the current age brackets being used (i.e. the 18-59 brackets) significantly reduces the usefulness of age in analyzing disaggregated data. Greater insights could be gathered around the age-based needs of populations served by Mercy Corps if age were collected using</span><span class="c2">&nbsp;</span><span class="c2 c9"><a class="c0" href="https://www.google.com/url?q=https://thedig.mercycorps.org/page/21&amp;sa=D&amp;ust=1471779169512000&amp;usg=AFQjCNGe-EGnyFOFGO8Kg7MJ0ibxA6YYzw">Mercy Corps&rsquo; recommended age brackets</a></span><span class="c2">, or preferably, collecting the exact age of household members as well as that of registered individuals. </span></p></div></body></html>""") 


ipython.display.HTML("""<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css">ol{margin:0;padding:0}table td,table th{padding:0}.c1{background-color:#ffffff;max-width:468pt;padding:72pt 72pt 72pt 72pt}.c2{orphans:2;widows:2}.c0{color:#4c515a;font-size:12pt}.title{padding-top:0pt;color:#000000;font-size:26pt;padding-bottom:3pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.subtitle{padding-top:0pt;color:#666666;font-size:15pt;padding-bottom:16pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}li{color:#000000;font-size:11pt;font-family:"Arial"}p{margin:0;color:#000000;font-size:11pt;font-family:"Arial"}h1{padding-top:20pt;color:#000000;font-size:20pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h2{padding-top:18pt;color:#000000;font-size:16pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h3{padding-top:16pt;color:#434343;font-size:14pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h4{padding-top:14pt;color:#666666;font-size:12pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h5{padding-top:12pt;color:#666666;font-size:11pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h6{padding-top:12pt;color:#666666;font-size:11pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;font-style:italic;orphans:2;widows:2;text-align:left}</style></head><body class="c1"><p class="c2"><span class="c0">The beneficiary population in Izmir, Turkey is a relatively even split between female/male, with a slightly higher female </span><span class="c0">population</span><span class="c0">. </span></p></body></html>""") 

+0

同じターゲットに対して2回のスタイルを挿入しているため、最後のものが残ります。また、 ''のような1回限りの2回のelemtensを挿入しています。 'ipython.display.HTML'がこれを世話しているかどうかわかりません。悪い書類。彼らがiframeであるかもしれませんか? –

+0

iframeは私の必要としているようですね。どのようにその仕事をするためのヒント? 'ipython.display.HTML'の呼び出しを' ipython.display.IFrame'の呼び出しで置き換えようとしましたが、出力に404エラーが表示されています。 –

+0

[ここ](http://superuser.com/questions/764641/how-to-ser--html-off-my-dropbox/931469#)で説明されているように、DropboxからHTMLファイルを提供することで、この作業を適切に行うことができました。 931469)。しかし、別の奇妙な問題が生まれました。私はノートブックにIFrameを含めました。コードセルを隠すために使用していたスクリプトをHTMLとしてダウンロードしたときに表示されなくなったため、動作しなくなりました。 –

答えて

1

Googleドキュメントのダウンロードから作成された完全なHTML文字列のIPython.display.HTMLへの複数の呼び出しにより、1つの文字列内のスタイリングが他のスタイリングと競合することが原因で問題が発生しました。

解決策は、IPython.display.HTMLへの呼び出しをIPython.display.IFrameへの呼び出しで置き換えるIFrameを使用することです。さらに、単にGoogle文書からダウンロードしたHTML文字列を含めるのではなく、HTML文書をWebサーバー上でホストして、ノートブックに正しくレンダリングする必要があります。 This postは、Dropboxを使ってファイルを提供する素晴らしいソリューションを提供します。

関連する問題