pio.write_image not working from within flask route
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 498
- Forks
- 62
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 2
Description
I am having an issue trying to store plotly image with command:
img = pio.write_image(fig=fig, file=fileName, format="png", width=800, height=500, scale=1, engine="kaleido")
It just hangs forever and cannot do anything.
I honestly do not know if this is plotly or kaleido issue. Funny thing is this only happens when within the Flask route. Same code works fine outside the route. For example, if I run this code:
def saveScreenshot_2(fig, width=800, height=500):
ic("def saveScreenShot_2")
"""Saves a Plotly figure as an image to a temporary file.
Args:
fig: The Plotly figure object.
width: The width of the image in pixels (default: 800).
height: The height of the image in pixels (default: 500).
Returns:
The path to the saved image file.
"""
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
try:
pio.write_image(fig=fig, format="png", file=temp_file.name, width=width, height=height, engine="kaleido")
ic("after pio.write_image")
return temp_file.name
except Exception as e:
print(f"Error saving image: {e}")
return None
outside the flask route, it works normally, but within flask route, it just hangs:
windows 10,
plotly.version: '5.24.1', kaleido.version: '0.2.1'
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided saveScreenshot_2 function and reproduce pio.write_image inside and outside a Flask route on Windows 10. Compare the behavior using Plotly 5.24.1 and Kaleido 0.2.1, then determine whether the hang is in the route context or image-export call. Done means the cause is identified and a verified fix or clear reproduction is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100