繁体   English   中英

如何在浏览器中查看 GraphViz SVG Graph?

[英]How to view GraphViz SVG Graph in Browser?

我想在我的 Web 服务(在 Flask 中)的浏览器页面中显示从输入文件生成的有向图,但是使用以下代码,我只能得到一个空白页面。 任何帮助都会让我度过一年,我开始对我对这段代码所做的许多变化感到生气。

这是我的图表的算法:

def _build_graph(self):
    dot = graphviz.Digraph("graph", format='svg')
    # then appending nodes and edges, but this works
    chart_output = dot.pipe().decode('utf-8')
    return chart_output

这是我的上传文件函数,从中生成和返回图表:

@app.route('/', methods=['POST'])
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # If the user does not select a file, the browser submits an
        # empty file without a filename.
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)

        if file and allowed_file(file.filename):
            sfilename = secure_filename(file.filename)
            output_path = os.path.join(app.config['UPLOAD_FOLDER'], sfilename)
            # Now save to this `output_path` and pass that same var to your mining function
            file.save(output_path)
            pro_file = preprocess(output_path) #this function takes the file and prepares it so it can be used in the build_graph function

            processed_file = build_graph(pro_file)
            return render_template('svg.html', processed_file=processed_file)

这是我的 svg.html:

{{ chart_output|safe }}

暂无
暂无

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

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