I have a html file named as “plot.html” in same directory with my streamlit program.
plot.html file content:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PyG2Plot</title>
<script type="text/javascript" src="https://unpkg.com/@antv/g2plot@2"></script>
</head>
<body>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body, div.pyg2plot-plot-container {
height: 100%;
overflow: hidden;
}
</style>
<div id="a5961f18d7644f7a9bc8de5aeb3c43cd" class="pyg2plot-plot-container"></div>
<script>
var plot_a5961f18d7644f7a9bc8de5aeb3c43cd = new G2Plot.Line("a5961f18d7644f7a9bc8de5aeb3c43cd", {
"data": [
{
"year": "1991",
"value": 3
},
{
"year": "1992",
"value": 4
},
{
"year": "1993",
"value": 3.5
},
{
"year": "1994",
"value": 5
},
{
"year": "1995",
"value": 4.9
},
{
"year": "1996",
"value": 6
},
{
"year": "1997",
"value": 7
},
{
"year": "1998",
"value": 9
},
{
"year": "1999",
"value": 13
}
],
"xField": "year",
"yField": "value"
});
plot_a5961f18d7644f7a9bc8de5aeb3c43cd.render();
</script>
</body>
</html>
I want to load it and show it in streamlit program, is there have some method?
import os
from requests_html import HTMLSession
from requests_file import FileAdapter
session = HTMLSession()
session.mount('file://', FileAdapter())
pwd = os.getcwd().replace("\\","/")
html_obj = session.get(f'file:///{pwd}/plot.html')
st.write(type(html_obj.text))
st.write(html_obj.text)
this code can show text content of plot.html, how to render or load its content in streamlit page?
I tried this:
import streamlit.components.v1 as html
html.iframe("http://localhost:8501/plot.html")
this will report 404: Not Found error.