简体   繁体   English

Django 中未显示嵌入式散景数据表

[英]Embedded Bokeh DataTable not showing in Django

I have developed a Django web application showing interactive maps generated by Bokeh, and sent to the templates as script/div using 'components' (from bokeh.embed).我开发了一个 Django Web 应用程序,显示由 Bokeh 生成的交互式地图,并使用“组件”(来自 bokeh.embed)将其作为脚本/div 发送到模板。 All items (figure, slider, title) are shown correctly except DataTable, which I can show in a standalone document or in Jupyter, but not with 'components'.除了 DataTable 之外的所有项目(图形、滑块、标题)都正确显示,我可以在独立文档或 Jupyter 中显示它,但不能在“组件”中显示。

I have read Bokeh DataTable not show in Flask , Embedding bokeh plot and datatable in flask and other threads, which helped me to fix the JS/CSS links, but it did not help with my problem.我读过Bokeh DataTable not show in FlaskEmbedding bokeh plot and datatable in Flask和其他线程,这帮助我修复了 JS/CSS 链接,但它对我的问题没有帮助。

I tried to wrap the DataTable inside different modules, like Panel, WidgetBox, etc., after reading https://github.com/bokeh/bokeh/issues/4507 , without success.在阅读https://github.com/bokeh/bokeh/issues/4507 后,我尝试将 DataTable 包装在不同的模块中,例如 Panel、WidgetBox 等,但没有成功。 For simplicity, I used example data with no link to my data to generate the table in a separate Django view, and created a separate template.为简单起见,我使用没有链接到我的数据的示例数据在单独的 Django 视图中生成表,并创建了一个单独的模板。

I have run out of ideas for now.我现在已经没有想法了。 I know that widgets in Bokeh have had rendering issues, so I am guessing my issue could be related to those issues, but more likely to my lack of knowledge.我知道 Bokeh 中的小部件存在渲染问题,所以我猜我的问题可能与这些问题有关,但更有可能是我缺乏知识。 The code is below.代码如下。

DJANGO VIEW : 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 TEMPLATE : 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 is blank: output as embedded table输出为内嵌表为空:输出为内嵌表

Output as standalone html works: output as standalone输出为独立的 html 作品:输出为独立

As bigreddot suggested, I opened the browser console, showing the following error messages when the DataTable is embedded in its original view/template:正如 bigreddot 所建议的那样,我打开了浏览器控制台,当 DataTable 嵌入到其原始视图/模板中时,显示以下错误消息:

browser console浏览器控制台

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM