为什么我在bokeh应用程序服务器中看不到情节? [英] Why am I not seeing plot in bokeh application server?
问题描述
我正在学习bokeh,正在申请.我使用文档bokeh serve --show app
中给出的架构运行目录,代码成功运行,并且按预期显示了模板和CSS的呈现,但是没有看到要生成的图.
I am learning bokeh and I am making an application. I ran the directory using the schema given in the documentation bokeh serve --show app
, the code runs successfully and I see the rendering of template and CSS as I expected, but I do not see the plot that I want to generate.
https://github.com/bokeh/bokeh/blob/master/examples/app/weather/main.py
我遵循了这个步骤,并且还查看了建议使用curdoc()
的Stackoverflow,但是我仍然看不到该图.我正在使用Python 3.6和Bokeh 0.13.0 Firefox 61.0和OS Ubuntu
I followed this and also looked on Stackoverflow where it was advised to use curdoc()
, but I still do not see the plot. I am using Python 3.6 and Bokeh 0.13.0 Firefox 61.0 and OS Ubuntu
这是我的main.py完整代码
This is my complete code for main.py
from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.layouts import row
p = figure(title='One sample graph',
plot_width=700,
plot_height=700,
toolbar_location=None)
p.circle([1,2,3,4,5],[6,7,2,5,4], size=15)
curdoc().add_root(row(p))
我还看着终端,看那里是否有任何错误.它也没有任何错误,当我查看HTML服务器的源代码时,没有看到用于生成绘图的代码.我想念什么吗?请帮忙.
I also looked at the terminal to see if there were any errors there. It also did not have any error and when I looked at the source code of HTML server, I did not see the code for generating the plot. Am I missing something? Please help.
我也看了下面的教程.该应用程序没有任何模板和CSS,也无法解决我的问题.
I looked at the following tutorial also. This has application without any templates and CSS and doesn't solve my problem.
这是终端的输出窗口.
Edit 2: Here is the output window of the terminal.
这是我仅运行bokeh serve --show main.py时的输出.在这种情况下,我只看到图并丢失了模板和CSS信息.我还下载了Chrome浏览器,以查看浏览器是否存在问题,但事实并非如此.
Here is the output when I simply run bokeh serve --show main.py In this case, I only see the plot and lose my template and CSS information. I have also downloaded Chrome to see if there was a problem with the browser, but it is not.
我在代码中缺少什么吗?在gitter上,我还被告知要使用server_document(),该语句应放在我的文档中的什么位置,以便正确呈现所有内容?
Am I missing something in my code? On gitter, I was informed of using server_document() also, where do I place that statement in my document so that everything gets rendered properly?
推荐答案
与bokeh serve --show appdir
一起运行时,显示templates/index.html
,但是原始模板不包含对embed
的任何调用以指定绘图位置,因此没有情节出现.必须在模板中调用embed
,以便Bokeh知道将图放置在何处.在index.html
中使用embed
的更新模板如下所示:
When running with bokeh serve --show appdir
, templates/index.html
displayed, but the original template did not contain any calls to embed
to specify where plots should go, so no plots showed up. It is necessary to call embed
in the template so that Bokeh knows where to put the plots. The updated template which uses embed
in index.html
looks like so:
main.py:
from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.layouts import row
p = figure(title='One sample graph',
plot_width=700,
plot_height=700,
toolbar_location=None)
p.circle([1,2,3,4,5],[6,7,2,5,4], size=15)
curdoc().add_root(row(p, name='plotrow'))
templates/index.html:
templates/index.html:
{% extends base %}
{% block preamble %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
<link rel="stylesheet" href="app/static/special.css">
{% endblock %}
{% block contents %}
<title>Dashboard</title>
<div class="background">
<div class="header">
<h1>Text</h1>
<h2>Some more text</h2>
<p>Even more text</p>
</div>
<div class="bar"></div>
<div class="container">{{ embed(roots.plotrow) }}</div>
<div class="footer">
<p>Some extra text <br/>By someone</p>
</div>
</div>
{% endblock %}
这篇关于为什么我在bokeh应用程序服务器中看不到情节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!