MediaFileManager: Missing file when try to plot two line chart on the same figure. sometimes it is working fine but most of the time doesn’t show anything
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
class Economics():
def demand_supply_cruve(self , data=None):
"""Graph demand and supply curve
inputs
--------------------------------
Data is a {price:[] , 'Demand':[1,2,3....] , 'Supply':[1,2,3,....] } per unit
"""
data = data if data != None else {'price':list(range(0,201,10)) ,'Demand':list(range(0,401,20))[::-1] , 'Supply':list(range(0,401,20))}
data = pd.DataFrame(data)
fig, ax = plt.subplots()
sns.lineplot( x=data["Demand"], y=data["price"])
sns.lineplot( data=data, x="Supply", y="price")
return fig
import streamlit as st
st.title("Eco")
eco = Economics()
st.pyplot(eco.demand_supply_cruve())
@AhmedSalam22 Thanks for letting us know. I think there’s an intermittent bug, and I have a fix. I’m for some testers; would you be willing to try it out with your use cases?
You can download the update from my dropbox.
First you uninstall streamlit
$ pip uninstall streamlit
Then you install the package using the wheel package.
Hi @anth! Welcome to the Streamlit Community and thanks for following up! I’m usually good about following up. These have been in the last release (0.69 I believe). Make sure you upgrade and try it out. If there’s still an issue, I can help you troubleshoot.
Hi @kmcgrady! Thanks for the quick response.
I checked that Im using streamlit==0.70.0 and I still have the same issue.
Since I’m new using Streamlit, I assume Im missing something here
When I test the Docker image locally, it works good, but after deployining it on a K8s cluster, it have the same issue showing some images. Here’s my setup: Dockerfile:
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)
I’ve implemented the with _lock: suggested by you , and it seems to help since the MediaFileManager: Missing file xx.png error raises less often, but the issue it’s still there.
The app its dockerize, and when I use it locally, it works perfectly, but after deploy it to Kubernetes, the issue shows up. It could be the same issue than 1294 on Github.
@anth I am so sad because I saw the first message while I was on vacation and a follow up on 1294, so I made the task to debug it when I got back. I ended up at the same conclusion as you. Multiple processes make things fail. I just wished I read the message above to save the debugging time .
I wrote up more in detail on the problem in the bug to avoid duplication of information. Needless to say, we can have a short term solution for Streamlit Share and trying to think of a broader solution for deploying outside. If you find Volumes to work, let me know (though I’m hesitant to believe it would…the process owns the memory).
Thanks for following up and pinging me. I appreciate it! These are some interesting challenges we’ll overcome.
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.