嗨,以下是我的代码:
app.py
from flask import Flask, render_template, render_template_string
from bokeh.embed import server_document
# app.py
# filename.py
app = Flask(__name__)
@app.route("/")
def index():
tag = server_document(url='http://127.0.0.1:5006/filename')
#return render_template('index.html', tag=tag)
return render_template_string('''<div>{{ tag|safe }}</div>''', tag=tag)
if __name__ == '__main__':
app.run()
filename.py
from numpy.random import random
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import column, widgetbox
from bokeh.models import Button, ColumnDataSource
# app.py
# filename.py
def click(n=100):
source.data = {'x': range(n), 'y': random(n)}
fig = figure(title='random data', width=800, height=400, tools='pan,box_zoom,reset,save')
source = ColumnDataSource(data={'x': [], 'y': []}) # place for data
fig.line('x', 'y', source=source) # draw plot
button = Button(label='update', button_type='success') # create button
button.on_click(click) # assign function to button
layout = column(fig, widgetbox(button)) # create layout
curdoc().add_root(layout) # add all to document
click() # generate random data at start
我跑步时
散景服务--show filename.py --allow-websocket-origin = 127.0.0.1:5000
或
背景虚化服务--show app.py --allow-websocket-origin = 127.0.0.1:5000
在我的笔记本电脑/ WindowsOS上,什么都没有显示。
这是正在运行的会话日志
(base) C:\Users\User\dev\pythonflaskapp>bokeh serve --show filename.py --allow-websocket-origin=127.0.0.1:5000
2020-06-14 22:17:59,380 Starting Bokeh server version 2.0.2 (running on Tornado 6.0.4)
2020-06-14 22:17:59,383 User authentication hooks NOT provided (default user enabled)
2020-06-14 22:17:59,387 Bokeh app running at: http://localhost:5006/filename
2020-06-14 22:17:59,387 Starting Bokeh server with process id: 12468
BokehDeprecationWarning: 'WidgetBox' is deprecated and will be removed in Bokeh 3.0, use 'bokeh.models.Column' instead
2020-06-14 22:18:00,141 404 GET /favicon.ico (127.0.0.1) 1.00ms
2020-06-14 22:18:00,152 Refusing websocket connection from Origin 'http://localhost:5006'; use --allow-websocket-origin=localhost:5006 or set BOKEH_ALLOW_WS_ORIGIN=localhost:5006 to permit this; currently we allow origins {'127.0.0.1:5000'}
2020-06-14 22:18:00,153 403 GET /filename/ws (127.0.0.1) 1.00ms
Interrupted, shutting down
(base) C:\Users\User\dev\pythonflaskapp>bokeh serve --show app.py --allow-websocket-origin=127.0.0.1:5000
2020-06-14 22:22:47,037 Starting Bokeh server version 2.0.2 (running on Tornado 6.0.4)
2020-06-14 22:22:47,040 User authentication hooks NOT provided (default user enabled)
2020-06-14 22:22:47,047 Bokeh app running at: http://localhost:5006/app
2020-06-14 22:22:47,047 Starting Bokeh server with process id: 12040
2020-06-14 22:22:47,965 404 GET /favicon.ico (127.0.0.1) 0.00ms
2020-06-14 22:22:47,977 Refusing websocket connection from Origin 'http://localhost:5006'; use --allow-websocket-origin=localhost:5006 or set BOKEH_ALLOW_WS_ORIGIN=localhost:5006 to permit this; currently we allow origins {'127.0.0.1:5000'}
2020-06-14 22:22:47,978 403 GET /app/ws (127.0.0.1) 2.00ms
Interrupted, shutting down
我可以知道我做错了什么吗?如何显示?
请帮助。感激。