我正在尝试使用google word trees和flask
构建wordtree数据可视化网站元素。你知道吗
我采用的方法基于this答案,包括尝试实现here建议的格式,我也尝试遵循this教程,但我的word_trees.html
只是不断呈现一个空白页。你知道吗
除了从一个更大的、虽然在实际应用中是等效的.csv
加载数据外,app.py
的相关部分包括:
from flask import Flask, render_template
import pandas as pd
import gviz_api
#create to data
lst = ["You've stolen a 'PIZZA' my heart! @CfgLaw Than",
"Did your workplace buy you pizza for #national",
"So last week on #NationalPizzaDay I had plans|",
"Last week it was #NewStartersDay and #National",
"@JurysInnsHotels #NationalPizzaDay Wow! I’m dr"]
df = pd.DataFrame({'text':lst})
#initiate app
app = Flask(__name__)
#create gvis formatted data
def get_data():
# Creating the data
description = {"text": ("string", "Text")}
data = [{"text":"{}".format(text)} for text in df.text]
# Loading it into gviz_api.DataTable
data_table = gviz_api.DataTable(description)
data_table.LoadData(data)
# Creating a JSon string
json_string = data_table.ToJSon()
return json_string
#pass data to template
@app.route("/")
def word_trees():
data = get_data()
return render_template('word_trees.html',tweets=data)
if __name__ == "__main__":
app.run(debug=True)
而word_trees.html
是:
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages:['wordtree']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable(tweets);
);
var options = {
wordtree: {
format: 'implicit',
word: 'pizza',
type: 'double'
}
};
var chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="wordtree_basic" style="width: 900px; height: 500px;"></div>
</body>
</html>
我希望应用程序根据df.text
中的数据呈现一个wordtree,但它一直呈现一个空白页面。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐