I have an api that returns an html (figure converted in html) and I'd like to show this html in my nextjs page but I dont know how. This is my api code:
@router.get("/graph/{id_file}", name="Return the graph obtained")
async def create_graph(id_file: str):
data = HAR.preparaDatos(id_file)
dataFinal = HAR.dataYprediccion(data, 'routes/modelo.h5')
fig = px.scatter(dataFinal, x=dataFinal['dateTimes'], y=dataFinal['nameActivities'])
ht=fig.to_html()
return HTMLResponse(ht)
And It returns this graph (in html): Graph
And this is my code in nextJS where I'm trying to show this graph:
<div className="grid">
<p className="description">
In this graph you can see the activity performed.
</p>
{isLoading && <p className="loading">Loading graph...</p>}
<p className="graph">
<script src={`http://127.0.0.1:8000/showGraph/graph/${id}`} />
</p>
But I can't finally see the graph on my page, does anyone know what might be wrong?
You can use Reacts dangerouslySetInnerHTML to render HTML into an element. https://reactjs.org/docs/dom-elements.html
<div dangerouslySetInnerHTML={{__html: yourHTML}} />