I’ve created a chart using pygwalker in a Jupyter Notebook:
...
visuals = pyg.walk(df, spec='pygwalker_spec_123456789.json')
visuals.chart_list
Output: ['Chart 1']
What I would like to do is save this predefined "Chart 1" as a PNG file in a Spyder script. Something like this:
visuals = pyg.walk(df, spec='pygwalker_spec_123456789.json')
visuals.save_chart_to_file('Chart 1', "chart_1.png")
But I get the following error:
ValueError: chart_name: Chart 1 not found, please confirm whether to save
When I check visuals.chart_list
, it returns an empty list []
, even though the 'pygwalker_spec_123456789.json'
file contains "Chart 1".
The reason I want to save the PNG via Spyder is to automate the entire process in a script so that my stakeholders receive all the PNG files automatically, without needing me to run the Jupyter notebook first.
Can anyone help me identify the error? Thank you!
pygwalker version 0.4.9.13
Pygwalker currently requires a frontend environment (like Jupyter Notebook or Streamlit) to render charts properly. This is why you're seeing different behavior between Jupyter and Spyder. When you use pygwalker.walk() in a pure Python environment like Spyder, the charts won't be generated in the same way they are in Jupyter. While there is a pre-release version that supports running pygwalker in a pure Python environment, it opens a webview to display charts rather than generating them directly in the script. For your automation needs, you might want to consider these alternatives:
Use a headless browser automation tool to run your Jupyter notebook Switch to a different visualization library that supports headless rendering (like matplotlib or plotly) Wait for future pygwalker releases that may add better support for headless environments
If you still want to use the pre-release version that supports pure Python environments, you can upgrade to the latest version, but be aware that it will open a webview window when walk() is called.
Related pre-release PR: https://github.com/Kanaries/pygwalker/pull/661