I’ve been attempting to use Plotly’s Kaleido to generate graph exports as images on the Streamlit Cloud backend but have been unable to get it to work, initially solved an issue due to no access to /tmp with the below:
import plotly.io as pio
pio.kaleido.scope.chromium_args = tuple([arg for arg in pio.kaleido.scope.chromium_args if arg != "--disable-dev-shm-usage"])
However now that I’ve jumped that hurdle it seems the page just hangs with ‘Running…’ whenever I try to generate an image like below:
It seems Streamlit Cloud may not be set up correctly to support the chromium process that Kaleido uses, which is rather disappointing seeing as the built in st.plotly_chart already provides some of the functionality but does not expose enough to allow getting the image in the python backend.
I explored trying various chromium command line arguments to no avail, as there are far too many for me to know what may or may not solve the issue.
Has anyone been able to find a solution to this? Or able to suggest one?
Could you elaborate more on the actual use-case you are trying to solve? Specifically, why export the picture to PNG, then load it as an image, than to just plot it as a Javascript visualization?
The real use case is to get the graph image into a word document using python-docx.
There are plenty of other uses for having the graphs exportable as well.
I am also having problems with kaleido. I wanted to use it to allow users to download the plotly graph being displayed on the app.The idea was to pass the result of fig.to_image() to st.download_button().
Surprisingly it works correctly when i run the app locally but not once it is hosted on streamlit cloud…
@florianbrnrd Yes, it’s an issue with streamlit cloud, and there’s no info in the log so really not sure whats happening. Would need some more info from @randyzwitch to know what may be able to get the process running.
@Franky1 It’s a private project, all the relevant code is in my original post.
I had success with explicitly setting these chromium options for kaleido on Streamlit Cloud:
# set explicit headless parameters for chromium (not sure if all are needed)
pio.kaleido.scope.chromium_args = (
"--headless",
"--no-sandbox",
"--single-process",
"--disable-gpu"
) # tuple with chromium args
install the latest versions of plotly and kaleido
don’t forget a “reboot” of streamlit app, that sometimes works wonders
Initially it worked, but seems its a 50/50 chance of working (or getting stuck into a ‘Running…’ state) after rebooting, perhaps they are still working on something back there?
I also tried with your chromium arguments and same issue.
Perhaps the bug is reintroduced when I try to get it into a word document (although it still sometimes happened when I removed this):
from docx import Document
from docx.shared import Inches
document = Document()
document.add_picture(io.BytesIO(fig_img), width=Inches(5.5))
This is working fine with an export from a graphviz graph:
For me it looks like kaleido is conflicting with the app when it is starting (getting stuck at the “app is in the oven” stage).
If i comment the function containing fig.to_image(format='png') then the app starts correctly. I then did a push to uncomment the function and it started working as intended…
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.