首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我无法让Flask中的Bokeh应用程序工作

我无法让Flask中的Bokeh应用程序工作
EN

Stack Overflow用户
提问于 2020-06-15 22:09:21
回答 1查看 203关注 0票数 0

嗨,下面是我的代码:

app.py

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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

当我跑的时候

bokeh服务--显示filename.py --允许-websocket-origin=127.0.0.1:5000

bokeh服务--显示app.py --允许-websocket-origin=127.0.0.1:5000

在我的笔记本电脑/WindowsOS上,什么也没有显示。

以下是正在运行的会话日志

代码语言:javascript
运行
复制
(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

我能知道我做错了什么吗?怎样才能显示出来呢?在我的c:/ app.py目录中,filename.py和app.py文件的放置位置有什么要求吗?

请帮帮忙。很感谢你。

EN

回答 1

Stack Overflow用户

发布于 2020-06-15 23:06:20

您是否尝试过提供--allow-websocket-origin=localhost:5006

它就在日志中:

代码语言:javascript
运行
复制
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'}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62389973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档