Ask coding questions

← Back to all posts
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?

Answered by VulcanWM [earned 5 cycles]
View Answer

yeah it is, do:


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.

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.

Any idea what I'm doing wrong?


@VulcanWM I figured it out. I had my bokeh code in the wrong place.

I corrected the project above that wasn't working, but I also created which uses the flask template better by just passing in the script components from bokeh.
Thanks for pointing me in the right direction!