Display PythonREPL graphics with Streamlit

So I’m trying to create a multi agent LLM application using Langgraph and Streamlit. With Langgraph’s official jupyter notebook, the chart_generator agent is able to produce and execute python code using PythonREPL. The graphics/plot display correctly on JupyterNotebook but when I try to use st.write() and st.image() to display the graphics/plot, it’s not showing up. Would love to get some pointers if anyone has any idea.

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed?
  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform?
    b. Share the link to the public deployed app.
  3. Share the link to your app’s public GitHub repository (including a requirements file).
  4. Share the full text of the error message (not a screenshot).
  5. Share the Streamlit and Python versions.

Hi @Lujia

If you can save the chart to file, you could use st.image() and you could also try one of several other methods mentioned in Chart elements - Streamlit Docs

Thanks for the speedy response.
But if you look into the code, the LLM agent is executing the Python code



@tool
def python_repl(
    code: Annotated[str, "The python code to execute to generate your chart."],
):
    """Use this to execute python code. If you want to see the output of a value,
    you should print it out with `print(...)`. This is visible to the user."""
    try:
        result = repl.run(code)
    except BaseException as e:
        return f"Failed to execute. Error: {repr(e)}"
    result_str = f"Successfully executed:\n```python\n{code}\n```\nStdout: {result}"
    return (
        result_str + "\n\nIf you have completed all tasks, respond with FINAL ANSWER."
    )```

Output in JupyterNotebook
![image|555x500](upload://p8ss67BnjmJW6VIltWniwwIIkW0.jpeg)

I haven't been able to find a way to save the chart and not sure how JupyterNotebook is displaying it.

In your tool instruct it to use plotly or st graphing functions not matplotlib

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.