0

我正在使用 Bokeh 库将数据可视化传递给 Django 项目。我能够通过标准的 Bokeh 可视化,但是当我尝试使用外部 wordcloud2 库时,我的项目崩溃了。我收到消息“发生服务器错误。请联系管理员。” 任何想法将不胜感激?!

使用的进口:

        from bokeh.plotting import figure, output_file, show
        from bokeh.embed import components
        # Bokeh WordCloud
        from bokeh.io import show
        from bokeh.models import ColumnDataSource
        from bokeh_wordcloud2 import WordCloud2

视图.py

下面的代码正在工作:

        x = [1,2,3,4,5]
        y = [1,2,3,4,5]

        plot = figure(title='Line Graph', x_axis_label='x_stuff', y_axis_label='y_stuff', plot_width=400, plot_height=400)
        plot.line(x, y, line_width=2)

        #auto_div - dynamically generates div elemetent
        script, auto_div = components(plot)

基于上面的示例,我试图以非常相似的方式传递 wordcloud 的值,但它不起作用:

        titles = ['lorem ipsum dolor sit amet',
                'consectetur adipiscing elit',
                'cras iaculis semper odio',
                'eu posuere urna vulputate sed']
        test1 = ColumnDataSource({'titles':titles})  
        wordcloud = WordCloud2(source=test1,wordCol="titles",color=['pink','blue','green']) 

        script, auto_div = components(wordcloud)

        context = {
            'script':script,
            'auto_div':auto_div,
        }

        return render(request, 'two_boxes/home.html', context)

根据我的测试,问题似乎出现在script, auto_div = components(wordcloud)声明中

主页.html

        <head>
        {% block bokeh_dependencies %}
        <link href="http://cdn.bokeh.org/bokeh/release/bokeh-1.3.4.min.css" rel=”stylesheet” type=”text/css”&gt;
        <link href="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.3.4.min.css" rel=”stylesheet” type=”text/css”&gt;

        <script src="http://cdn.bokeh.org/bokeh/release/bokeh-1.3.4.min.js"></script>
        <script src="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.3.4.min.js"></script>
        {{ script | safe }}
        {% endblock %}
        </head>

        <body>
        <h1>Bokeh Stuff</h1>
        {{ auto_div | safe }}
        </body>

资源:

https://hackernoon.com/integrating-bokeh-visualisations-into-django-projects-a1c01a16b67a https://github.com/joranbeasley/bokeh_wordcloud2

4

0 回答 0