個人の Web サイトにボケ プロットを静的に埋め込もうとしていますが、理解できない動作に遭遇しています。基本的に、次のようにボケを使用してプロットを生成しています。
import bokeh.plotting as bplt
import numpy as np
x=np.random.random(100)
y=np.random.random(100)
bplt.output_file("t.html")
plot=bplt.line(x,y)
##the following line refers to the bokeh installed on my home computer
print plot.create_html_snippet(
static_path='/usr/local/lib/python2.7/site-packages/bokeh/server/static/')
##the following line refers to the bokeh installed on my remote computer
#print plot.create_html_snippet(
# static_path='/opt/anaconda/lib/python2.7/site-packages/bokeh/server/static/')
ここまでは順調ですね。これにより、次のようなファイルが生成(random garbage).embed.js
され、 と呼んでいる html ファイルに手動でコピーした html 構文を含む文字列が出力されますtestembed.html
。これを以下に再現しました。
<html>
<body>
<h2>Simple Embed Example</h2>
<p>This is where my plot should be:</p>
<p>
<!--The next 4 lines are the output of the print statement from the python code-->
<script src="ccbd451a-6995-4dd2-b99c-e4140b362997.embed.js"
bokeh_plottype="embeddata"
bokeh_modelid="ccbd451a-6995-4dd2-b99c-e4140b362997"
bokeh_modeltype="Plot" async="true"></script>
</p>
</body>
</html>
Python コードでローカルのPython インストールを参照し、生成されたファイル (.html および .embed.js) をローカル コンピューターにコピーすると、html ファイルにプロットが表示されます。
しかし、私が本当にやりたいことは、これをリモート コンピューターで実行し、個人用サイトの Web 経由で html ファイルにアクセスできるようにすることです。
リモート コンピューターのpython インストールをstatic_path
参照すると(上記のようにコメント アウトされています) 、Web 経由でアクセスすると (つまり、 http://mywebsite.com/に移動すると) 、html ページにプロットが表示されません。 testembed.html )。なぜこれが起こっているのか分かりません。
参考までに、htmlスニペット関数が定義されているコードは次のとおりです
。、つまり 、 これと関係がある可能性があります。create_html_snippet
embed_base_url
前もって感謝します!マイク
EDIT
私はbigreddot
問題を解決したのアドバイスを受けました。私が抱えていた実際の問題は、私が使用していた Web サーバーが、セキュリティ上の理由から、自分のpublic_html
ディレクトリ内のものにしかアクセスできないことでした。回避策はrsync
、bokeh/static
ディレクトリを my に移動し、public_html
それを指すことでした:
rsync -ax /opt/anaconda/lib/python2.7/site-packages/bokeh/server/static/ /home/myusername/public_html/bokeh-static/
次に、次のようにコードを変更します。
import bokeh.plotting as bplt
import numpy as np
x=np.random.random(100)
y=np.random.random(100)
bplt.output_file("t.html")
plot=bplt.line(x,y)
#the following line refers to the bokeh rsynced to my directory
print plot.create_html_snippet(
static_path='http://www.my_server_website/~myusername/bokeh-static/',
embed_base_url = 'http://www.my_server_website/~myusername/where_.js_file_is_located')
そして、生成されたhtmlを明らかにコピーしますtestembed.html
。