我开发了一个Django web应用程序,显示Bokeh生成的交互式地图,并使用“components”(来自Bokeh.embed)以script/div的形式发送到模板。所有项目(图、滑块、标题)均正确显示,但DataTable除外,我可以在独立文档或Jupyter中显示DataTable,但不能使用“组件”
我读过Bokeh DataTable not show in Flask、Embedding bokeh plot and datatable in flask和其他线程,它们帮助我修复了JS/CSS链接,但对我的问题没有帮助
在阅读了https://github.com/bokeh/bokeh/issues/4507之后,我尝试将DataTable包装到不同的模块中,如Panel、WidgetBox等,但没有成功。为了简单起见,我使用没有数据链接的示例数据在单独的Django视图中生成表,并创建了一个单独的模板
我现在已经没有主意了。我知道Bokeh中的小部件存在渲染问题,所以我猜我的问题可能与这些问题有关,但更可能与我缺乏知识有关。代码如下
DJANGO视图:
def datatable_test(request):
data = dict(
dates=[date(2014, 3, i + 1) for i in range(10)],
downloads=[randint(0, 100) for i in range(10)],
)
source = ColumnDataSource(data)
columns = [
TableColumn(field="dates", title="Date", formatter=DateFormatter()),
TableColumn(field="downloads", title="Downloads"),
]
data_table_mth = DataTable(source=source, columns=columns, width=400, height=280)
layout = column(
Spacer(width=100),
WidgetBox(data_table_mth),
)
script_table, div_table = components(layout)
output_file("DATATABLE TEST.html")
show(layout)
return render(request, 'integrated/datatable_test.html', {'script_table': script_table,'div_table': div_table})
DJANGO模板:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% block title %}{% endblock %}</title>
<link href="https://cdn.bokeh.org/bokeh/release/bokeh-1.4.0.min.css" rel="stylesheet" type="text/css">
<link href="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.4.0.min.css" rel="stylesheet" type="text/css">
<link href="https://cdn.bokeh.org/bokeh/release/bokeh-tables-1.4.0.min.css" rel="stylesheet" type="text/css">
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-1.4.0.min.js"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.4.0.min.js"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-1.4.0.min.js"></script>
{{ script_table | safe }}
</head>
<body>
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-success">
<div class="box-body">
{{ div_table | safe }}
</div>
</div>
</div>
</div>
</section>
</body>
作为嵌入表输出为空: output as embedded table
作为独立html工作的输出: output as standalone
正如bigreddot所建议的,我打开了浏览器控制台,当DataTable嵌入到其原始视图/模板中时,显示了以下错误消息:
browser console
相关问题 更多 >
编程相关推荐