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
Images sometimes do not appear #1294
Comments
Hi @nthmost, Is this bug fixed? It's causing a lot of trouble for me, and I'd love to upgrade if it's fixed. Unfortunately it's not trivial for me to check if it's fixed or not, because of two reasons:
I'd rather not suffer with the upgrade unless it's worth it, so even a simple yes/no would be greatly helpful. (A timeline if no is the answer, even more so.) |
Hi @danielvarga , The fix was merged 5 days ago. It's available now on the nightly build. SessionState should work fine with the current version of Streamlit. Have you tried with the updated gist? |
Thanks! I haven't tried until you brought it to my attention, now I have. Indeed it seems to fix issue #1294, thanks a lot! But my code does not fully work with the new version, as it broke this hack by Tim Conkling: https://discuss.streamlit.io/t/show-more-items-functionality/1139/2 (Sorry for moving off topic. I'll stop discussing it here, and raise the issue there.) |
Still experiencing an issue with this one, even on nightly (v0.59.1.dev20200506). Can see the issue with Seeing these errors scattered in the console...
|
I can confirm this is still an issue in Edit: For people Googling, we "solved" this by downgrading to |
Indeed, I was too quick to report that the issue is gone, sorry, it was probably just a statistical fluke. Frequency of occurrence might or might not have decreased, hard to tell. |
I am experiencing the same behaviour with matplotlib plot that the are generated with input from sliders. Is this covered under this issue or should I create a new one? |
I have the same issue. I am trying to display two different pyplot charts on the same script, more often than not the first chart is not displayed. |
Same issue on my side with the version 0.61. It happens when displaying 2 pie chart created by the same function called twice. The first st.pyplot is not displayed. Edit : adding a sleep(0.2) after the pyplot() seems work as workaround |
I have the same issue, when using streamlit==0.61.0. Images will randomly be displayed as 0s. |
Tried it with the current streamlit-nightly==0.62.1.dev20200621 and the issue still appears there as well, though perhaps a bit less often. |
@KyotoSunshine -- is it possible you can share a snippet of code that causes the problem to occur? |
In my script that it shows 8 charts taken data by csv, with the version 0.56.0 was all ok (in local, in docker container local and in docker container on app engine (GCP)). Other problem: with the latest version (0.62.0) the script is slower to execute |
Hi @MauGal, could you share sample code that we can copy/paste and run to reproduce the issue? I'll be sure to try it both locally and on GCP. Also, could you give a bit more info on what you're seeing with regards to the script being slower to execute? |
Hi @jrhone . |
Hi, |
Hi @chakra-ai ! It will be really difficult to debug without being able to run the code, so if you are able to share your code (or better, provide a toy example that illustrates the problem simply, that would make life a lot easier. Here are a couple thoughts that might help us solve the problem. The MediaFileManager manages all the media in memory. At the end of the script run, all media that was not used in that run, is deleted (to conserve memory). Based on this, we should ensure everything working though I’m curious with race cases (for example, is this an issue with multiple people requesting the website, perhaps that causes a problem)? Does this occur standalone when one user interacts with it? MatPlotlib is unfortunately not thread safe. So, one should not use st.pyplot with no figure. Even more protection is needed and matplotlib offers a locking mechanism, In another application, I wrote: import matplotlib
from matplotlib.figure import Figure
matplotlib.use("agg")
_lock = RendererAgg.lock
# ...code...
with _lock:
fig = Figure()
ax = fig.subplots()
# ...perform work on ax
st.pyplot(fig) You can see it in action here: https://github.com/kmcgrady/book_reco/blob/master/books.py#L16 Hopefully that helps with a solution. If not and you can provide a simple example that causes the problem, please let me know. |
Hi @kmcgrady , Thanks for the quick reply. The issue of image rendering I am facing is mostly after I deploy to azure machine. In local its working. I have 2 parts to it.
And the image rendering happens like shown below; It would be great if you can help on this. Thanks. |
Adding to the above issue; while I inspect the application on the browser for the image component, the image url generated as; In the console I see; GET https:///media/1b25254261af69495b4fc9a637472aacad81157493ba5f698288e9da.png 404 status. for the broken image. |
@chakra-ai hmmmmm. I wonder if you can get logs from the server or perhaps run it in debug logging mode? I wonder if there's some caching layer in Azure that's breaking. The sidebar logo, should not be a problem at the very least, so I'd target that as a trivial example to see if we can deduce why that image cannot appear. Alternatively, I wonder if you deploy the application on Streamlit Share, does the issue still occur? |
hey @kmcgrady, i'm having this issue on Streamlit Share with my books app (https://share.streamlit.io/tylerjrichards/book_reco/books.py) this only happens on Streamlit sharing, but doesn't happen when I run the app locally. Any ideas? |
@tylerjrichards I'll take a look and see if I can figure out the problem. It will be a couple weeks due to the holidays. I'll put something on my calendar in my new year to follow up. |
Hey @tylerjrichards Just want to follow up. I spent some time today investigating it. I am reasonably confident on the problem and can reproduce it. In essence:
I had trouble by uploading the same code to my personal Streamlit share because there was no problem. That is because my service is only one process. When a process gets too much attention (as in your case when we marketed it for Streamlit Share), we add more resources to it and now we have multiple processes causing the issue. I was able to demonstrate this on my system by upping the number of processes. So the easy workaround for you is to delete the app and redeploy it (thereby making it seem like a new single process app for now). I believe that would work and would bypass some internal communication chain to reduce resources. If the app gets more attention, we can increase those resources again, but hopefully we'll have a fix in time. If you do that, let me know if that works/doesn't work. If that's unacceptable, I can look through my end and see if I can reduce the resources, just a little more red tape. To summarize for @chakra-ai I wonder if your Azure solution is creating multiple processes (at least more than 1) and creates the same problem above. If that's the case, I don't have a clear solution. We are spending a lot of time figuring our the solution for Streamlit Share that I can't speak for on Azure, but I am bringing it up as a big point for the team to think about prioritization at the very least. |
hey @kmcgrady! Thank you for the incredibly detailed response. I've been trying to fix this issue on my end as well the past couple days. I tried the solution of just deleting the app and redeploying it, but even after a day of the app being in the oven, it never actually built. thank you for your help, i'm super grateful for it. |
Thanks @tylerjrichards! I informed our cloud team of the challenge you had redeploying. Hopefully they'll sort something out. Glad redeploying under a name worked. |
I am still facing the same issue, any help is appreciated |
Hey Suvoo, can you open a new bug and include some more info? In particular:
Thanks! |
While this works totally fine. I don't see why this happens |
Thanks Suvoo. I just encountered this issue and your workaround using PIL fixed it. Streamlit, version 0.73.0, Windows 10. What baffles me is that the st.image/st.sidebar.image call is in a page base class for a multi-page app that has been running reliably for over a year - I'm getting this testing standalone a new page subclassed from the same base class as the others. It's the first time I've ever seen this issue. Weird. @tvst This is happening in the application we talked about a while back. Here's a screen snip of a test. The sidebar image is using Suvoo's workaround, the main frame one is the same filepath but provided directly to st.image. The sidebar one is called from the base class, the main frame from the sub-classed application page Kevin |
I was having this same issue when deploying to GCP App Engine and was able to solve it with help from the @kmcgrady post above (thank you!). The key is multiple instances. If you use the default configs on App Engine you are going to have multiple instances (VMs) underlying your application and this is going to cause 404s to from the HTTP image fetch outside the websocket. When I force the instance count to 1, this issue goes away and all of the images render properly. Of course, I loose autoscaling which isn't ideal but at least the app works properly. |
For those using GKE you can resolve this by making sure the application container's replicas is set to one
|
I had "0" showing instead of an image when trying to get the image from a server. My mistake was not writing "http://" before the url. adding it resolved the problem. |
Hi, is there any workaround for this? I'm deploying to GCP and several images are generated dynamically, so when using multiple instances some of them are replaces by the "0" and some of them are displayed. Of course this is not optimal and we're hoping to use Streamlit in production, but at the moment there's no reliable way to display all the images consistently. Is this address by Streamlit somehow or it's not fixable and should I try another library? |
Hi there, I'm having the same issue. When I run the app locally it works fine, but when I deploy on Heroku, random plots everytime show "0" instead. I'm not even loading an image, what I'm doing is:
I'm having multiple pieces of code like this with different plots in the same streamlit page, every time, some are shown and some are not but they are not always the same. |
Streamlit, version 1.8.1 still has the issue ... 2022-04-20 08:45:37.024 InMemoryFileManager: Missing file 8f38e6ff47a0a683fe589238cf5f5db9c04efeaf6ed930e129ea082e.png |
Same problem (Streamlit 1.8.1): 2022-04-28 10:53:36.820 InMemoryFileManager: Missing file c669431943be2067b62db57fdf9ba81deec9f17f2bdfaaa2df6fdc09.png |
Can confirm the issue. Only occurs in deployment though, not when running streamlit locally. It's a simple st.image("logo.webp") Error message: InMemoryFileManager: Missing file 1156bb4e04fc0aaf71e4a8dfcf917b11a54797812e23e860bf0dae28.jpeg |
Facing the same issue with version This error shows: I'm using |
I see numerous more cases of this issue happening in this thread. To be clear, here's what goes on below the hood:
With that in mind, this leads to some important outcomes.
Outside of above, if you have a simple code example/repro steps to demonstrate the issue. It would be very helpful. |
Thanks for explaining the problem. My app runs with replicas behind a load balancer, I solved the 0-image problem by using sticky routing. Adding the sticky-cookies-services annotation here worked for me. |
FYI in case other folks come across this, we were able to fix our images loading issue with this: |
My team solved this issue on Kubernetes on Azure by enabling Cookie Based Affinity, https://azure.github.io/application-gateway-kubernetes-ingress/features/cookie-affinity/ |
Summary
The site randomly shows "0" for images inserted via st.image() and MediaFileManager logs "Missing file".
More information
I have a couple of jpg images embedded with st.image() and randomly they will not render, instead there will just be a 0 shown instead. Reloading the page or rerunning the code fixes the problem. When I reload the page often enough one ore several of the images will break again and just show a 0.
In the terminal with --log_level error I receive
In my complex multi-page streamlit app this happens very often, if I reload the page two or three times, one out of five images is likely broken. The simpler toy example below takes much longer to show the undesired behaviour, but it does so fairly consistently.
Steps to reproduce
Run this code (ideally with --log_level error):
Toggle that checkbox repeatedly (this method is quicker than reloading the page) and look at the console output. Maybe rerun the code once in a while. (Of course you need to put any jpg image named "foo.jpg" in the same folder).
Actual behaviour
Sooner or later (5-50 clicks) the image will not be shown. Instead, in its place a 0 appears. A "MediaFileManager: Missing file" error is shown in the terminal.
Expected behaviour
Images should always be shown.
Debug info
The text was updated successfully, but these errors were encountered: