Streamlit server consistently failed status check

I keep getting the following error. I’ve tried rebooting, and deleting the app and posting it again. I never get this error when I’m running the app locally. Only when I publish it to streamlit:

[17:03:07] 📦 Processed dependencies!


Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.

/app/und_adp/Und_Visual_ADP_App.py:127: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

  plt.scatter(adp_risers_fallers['ADP Change'], adp_risers_fallers.index, s=1500, alpha=.6, color=adp_risers_fallers.colors)

2023-05-22 21:19:06.829 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/und_adp/Und_Visual_ADP_App.py", line 127, in <module>

    plt.scatter(adp_risers_fallers['ADP Change'], adp_risers_fallers.index, s=1500, alpha=.6, color=adp_risers_fallers.colors)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2890, in scatter

    __ret = gca().scatter(

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2368, in gca

    return gcf().gca(**kwargs)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 2065, in gca

    return self.add_subplot(1, 1, 1, **kwargs)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 1404, in add_subplot

    return self._add_axes_internal(key, ax)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 1408, in _add_axes_internal

    self._axstack.add(key, ax)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 125, in add

    super().remove((key, a_existing))

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 643, in remove

    raise ValueError('Given element not contained in the stack')

ValueError: Given element not contained in the stack

/app/und_adp/Und_Visual_ADP_App.py:127: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

  plt.scatter(adp_risers_fallers['ADP Change'], adp_risers_fallers.index, s=1500, alpha=.6, color=adp_risers_fallers.colors)

2023-05-22 21:43:03.253 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/und_adp/Und_Visual_ADP_App.py", line 127, in <module>

    plt.scatter(adp_risers_fallers['ADP Change'], adp_risers_fallers.index, s=1500, alpha=.6, color=adp_risers_fallers.colors)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2896, in scatter

    sci(__ret)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/pyplot.py", line 3102, in sci

    return gca()._sci(im)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2368, in gca

    return gcf().gca(**kwargs)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 2065, in gca

    return self.add_subplot(1, 1, 1, **kwargs)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 1404, in add_subplot

    return self._add_axes_internal(key, ax)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 1408, in _add_axes_internal

    self._axstack.add(key, ax)

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/figure.py", line 125, in add

    super().remove((key, a_existing))

  File "/home/appuser/venv/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 643, in remove

    raise ValueError('Given element not contained in the stack')

ValueError: Given element not contained in the stack

[22:20:58] ❗️ Streamlit server consistently failed status checks

[22:20:58] ❗️ Please fix the errors, push an update to the git repo, or reboot the app.```


Links:
Repo: GitHub - nzylakffa/und_adp
App: https://nzylakffa-und-adp-und-visual-adp-app-nzmny4.streamlit.app/

Requirements File:

lxml==4.9.1
matplotlib==3.3.3

Hey @nzylakffa,

Any chance you’re using matplotlib with multiple threads? I found this StackOverflow post which seems to be similar and identifies that as the root cause

Would you mind explaining what that means? I’m not sure what multiple threads are. This is the section where I use matplotlib:

# Draw plot
    fig = plt.figure(figsize=(14,16), dpi= 80)
    plt.scatter(adp_risers_fallers['ADP Change'], adp_risers_fallers.index, s=1500, alpha=.6, color=adp_risers_fallers.colors)
    for x, y, tex in zip(adp_risers_fallers['ADP Change'], adp_risers_fallers.index, adp_risers_fallers['ADP Change']):
        t = plt.text(x, y, round(tex, 1), horizontalalignment='center', 
                     verticalalignment='center', fontdict={'color':'white',
                                                           'size': 15})
    
    # Create start and end dates for title
    start_text = str(start_date)
    end_text = str(end_date)

    # Only keep month and day
    start_text = start_text[5:]
    end_text = end_text[5:]

    # Decorations
    # Lighten borders
    plt.gca().spines["top"].set_alpha(.3)
    plt.gca().spines["bottom"].set_alpha(.3)
    plt.gca().spines["right"].set_alpha(.3)
    plt.gca().spines["left"].set_alpha(.3)

    plt.yticks(adp_risers_fallers.index, adp_risers_fallers['Player'], fontsize=17)
    plt.xticks(fontsize = 17)
    plt.title('10 Biggest Risers & Fallers: ' + start_text + ' -> ' + end_text, fontdict={'size':30})
    plt.xlabel('Change in Underdog ADP', fontdict={'size': 20})
    plt.grid(linestyle='--', alpha=0.5)
    plt.xlim(min(adp_risers_fallers['ADP Change'])-1, max(adp_risers_fallers['ADP Change'])+1)
    plt.axvline(x=0, color='gray', linewidth=0.75)
    st.pyplot(fig)```