Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
Show HTML element in NextJS

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?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use Reacts dangerouslySetInnerHTML to render HTML into an element. https://reactjs.org/docs/dom-elements.html

<div dangerouslySetInnerHTML={{__html: yourHTML}} />
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda