Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error with img build in method decode bytes – Dash plotly

I can’t upload a img to my app, when i try i just got a "broken image".

i’m using this piece of code, the only piece of method that i found on plotly forum.

encoded_image = base64.b64encode(open(r'\path\img.png', 'rb').read())
html.Div([
    html.Img(id='image_png', src='data:image/png;base64,{}'.format((encoded_image.decode)))

Inspecting my app page, this error is present

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<img id="logo_png" src="data:image/png;base64,<built-in method decode of bytes object at 0x000002B70136AE30>">

>Solution :

You should use decode() function correctly as follows:

import dash
from dash import html
import base64

app = dash.Dash()

image_filename = './child.png'
encoded_image = base64.b64encode(open(image_filename, 'rb').read()).decode()

app.layout = html.Div([
    html.Img(src='data:image/png;base64,{}'.format(encoded_image))
])

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading