【发布时间】:2019-02-07 20:20:09
【问题描述】:
我“继承”了一个更大的软件项目,在后端使用 python/flask,在前端使用 HTML/Javascript。我现在想在其中一个网站上实现一些交互性。 我成功地将数据框传递到网页并可以显示其内容。我有一些过滤器作为按钮,可以在各种视图之间切换。我可以在网页本身中访问这些过滤器值。我现在如何将这些新值传递给数据框以过滤它而不必重新渲染整个页面? 请注意,我使用 template.render() 而不是 render_templates() 因为该项目没有模板文件夹,并且需要进行太多重组才能更改此内容。 这是相关的python部分:
@app.route('/tagging/OverviewPerDoc.html')
def analysis():
x = <function which returns a pandas dataframe>()
tempid = globalxmlid
datatuple = [x, tempid]
filetoopen = os.path.join(os.getcwd(), config.filepaths.overviewperdoc)
with open(filetoopen) as fi:
template = Template(fi.read())
return template.render(data = datatuple)
这是网站部分:
<body>
(...)
<button id="magicbutton" class="btn btn-primary my-group-button" type="submit" style="margin-right:5px;" value = "Show">Show</button>
(...)
{% block content %}
(...)
</div> <br> <br> <br>
<h1 align="center">{{data[0][data[0]['identifier'] == data[1]]['Name'].iloc[0]}}</h1>
(...)
<div class="container">
<table>
<tr>
<th></th>
(...)
<tr>
<td>Value</td>
<td>{{data[0][data[0]['identifier'] == data[1]]['Value'].iloc[0]}} {{data[0][data[0]['identifier'] == data[1]]['currency'].iloc[0]}}</td>
<td>100%</td>
</tr>
(...)
当单击我的测试按钮时,我可以将其值打印到控制台。
<script>
function magicfunction()
{
var test = savethecurrentxml;
console.log(test);
}
</script>
正如我所说,所有这些都有效,我现在只想将其更改为:
data[0][data[0]['identifier'] == test]['Name'].iloc[0]
我怎样才能做到这一点?
【问题讨论】:
标签: javascript python html pandas flask