Black Lives Matter. Please consider donating to Black Girls Code today.

Download PNG with urllib

Hello! Im making my dashboard and im trying to make standalone button to save plot as png.
A trying to save raw data to png file with

  • img_bytes = py.image.get({
    ‘data’: […],
    ‘layout’:
    go.Layout(…
    ‘png’,scale=1)

I get this bytes and i can read it with

  • print(img_bytes).

After that i use

  • stringpic = “data:image/png;base64,” + urllib.parse.quote(str(img))

But then I trying to download it with html.A(html.Button(…)) component I get the error with file, in dowload bar in browser i see “Network error”. I`ve tried to save pytes in csv file and it worket, I got the csv file bytes.

Is it possible to save PNG this way, or i can only use 'download plot as png" button on top of graphic ?

Cross reference: Encode png bytes to base64

Does this answer also address your issue here?