Skip to content

Commit

Permalink
Guard all operations on figure by RenderedAgg.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Amey-D committed Oct 9, 2020
1 parent 3bb735f commit 62b7f8b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions COVID_app.py
Expand Up @@ -28,6 +28,9 @@
plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
plt.rcParams['figure.figsize'] = 8, 8

from matplotlib.backends.backend_agg import RendererAgg
_lock = RendererAgg.lock


#st.beta_set_page_config(page_title="COVID19: EpiCenter for Disease Dynamics",
# page_icon="signal",
Expand Down Expand Up @@ -242,12 +245,13 @@ def get_testing_data(County):
ax3.set_ylabel('Number of individuals')
ax4.set_ylabel('per 100 thousand')

if len(county)<6:
fig.suptitle('Current situation of COVID-19 cases in '+', '.join(map(str, county))+' county ('+ str(today)+')')
else:
fig.suptitle('Current situation of COVID-19 cases in California ('+ str(today)+')')
fig.tight_layout(rect=[0, 0.03, 1, 0.95])
st.pyplot(fig)
with _lock:
if len(county)<6:
fig.suptitle('Current situation of COVID-19 cases in '+', '.join(map(str, county))+' county ('+ str(today)+')')
else:
fig.suptitle('Current situation of COVID-19 cases in California ('+ str(today)+')')
fig.tight_layout(rect=[0, 0.03, 1, 0.95])
st.pyplot(fig)

import streamlit.components.v1 as components
if len(county)<=3:
Expand Down Expand Up @@ -390,9 +394,10 @@ def get_testing_data_state():
ax4.set_title('(A) Weekly rolling mean of incidence per 100k')
ax3.set_ylabel('Number of individuals')
ax4.set_ylabel('per 100 thousand')
fig.suptitle('Current situation of COVID-19 cases in California ('+ str(today)+')')
fig.tight_layout(rect=[0, 0.03, 1, 0.95])
st.pyplot(fig)
with _lock:
fig.suptitle('Current situation of COVID-19 cases in California ('+ str(today)+')')
fig.tight_layout(rect=[0, 0.03, 1, 0.95])
st.pyplot(fig)


@st.cache(ttl=3*60*60, suppress_st_warning=True)
Expand Down

0 comments on commit 62b7f8b

Please sign in to comment.