Can a python file display html output?
I am using the bokeh library with python which generates an html/js file as output to display data visualizations. I would like to be able to display/render the html from within the python file, but can't figure out how to do that.
For now, the only workarounds I have found are:
1) create a separate html project and copy/paste the html file contents from the python project into the html project.
2) download the html file from the python project and open it in my browser.
Is it possible to view the html output from within the python project?
yeah it is, do:
from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): return render_template(template_name) app.run(host='0.0.0.0', port=8080, debug=True)
Thanks, that works if I have an html file that I've already generated, but I can't get it to work when I try to use flask with bokeh in the same project.
Here is a project where I use flask to render html that I generated from bokeh in another project. It works. https://replit.com/@JamesonMcGee/flask-site-demo#main.py
Here is a project where I use bokeh to generate the html and then try to use flask to render it. It doesn't work. https://replit.com/@JamesonMcGee/bokeh#main.py
Any idea what I'm doing wrong?
@VulcanWM I figured it out. I had my bokeh code in the wrong place.
from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): # insert bokeh code here return render_template(template_name) app.run(host='0.0.0.0', port=8080, debug=True)
I corrected the project above that wasn't working, but I also created https://replit.com/@JamesonMcGee/bokehflask#main.py which uses the flask template better by just passing in the script components from bokeh.
Thanks for pointing me in the right direction!