Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pio.write_image not working from within flask route #238

Open
grega913 opened this issue Dec 27, 2024 · 0 comments
Open

pio.write_image not working from within flask route #238

grega913 opened this issue Dec 27, 2024 · 0 comments

Comments

@grega913
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant