-
Notifications
You must be signed in to change notification settings - Fork 5
/
covid_menu_streamlit.py
151 lines (140 loc) · 7.71 KB
/
covid_menu_streamlit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import streamlit as st
import importlib
import traceback
st.set_page_config(page_title="COVID SCRIPTS of René Smit", layout="wide")
def show_info():
tekst = (
"<style> .infobox { background-color: lightblue; padding: 5px;}</style>"
"<hr><div class='infobox'>Made by Rene Smit. (<a href='http://www.twitter.com/rcsmit' target=\"_blank\">@rcsmit</a>) <br>"
'Sourcecode : <a href="https://github.com/rcsmit/COVIDcases/blob/main/covid_dashboard_rcsmit.py" target="_blank">github.com/rcsmit</a><br>'
'How-to tutorial : <a href="https://rcsmit.medium.com/making-interactive-webbased-graphs-with-python-and-streamlit-a9fecf58dd4d" target="_blank">rcsmit.medium.com</a><br>'
)
st.sidebar.markdown(tekst, unsafe_allow_html=True)
def dynamic_import(module):
"""Import a module stored in a variable
Args:
module (string): The module to import
Returns:
the module you want
"""
return importlib.import_module(module)
def main():
st.title ("COVID SCRIPTS of René Smit -")
# [n. name in menu, module name]
options = [["[0] welcome","welcome"],
["[1] covid dashboard","covid dashboard rcsmit"],
["[2] plot hosp ic per age","plot hosp ic streamlit"],
["[3] false positive rate covid test","calculate false positive rate covid test streamlit"],
["[4] number of cases interactive","number of cases interactive"],
["[5] ifr from prevalence","calculate_ifr_from_prevalence_streamlit"],
["[6] fit to data","fit to data streamlit"],
["[7] SEIR hobbeland","SEIR hobbeland"],
["[8] show contactmatrix","show contactmatrix"],
["[9] r getal per provincie","r getal per provincie"],
["[10] Cases from suspectibles", "cases_from_susp_streamlit"],
["[11] Fit to data OWID", "fit_to_data_owid_streamlit_animated"],
["[12] Calculate R per country owid", "calculate_r_per_country_owid_streamlit"],
["[13] Covid dashboard OWID/Google or Waze","covid dashboard owid"],
["[14] Dag verschillen per leeftijd", "dag_verschillen_casus_landelijk"],
["[15] Calculate spec]/abs. humidity from rel. hum", "rh2q"],
["[16] R getal per leeftijdscategorie", "r_number_by_age"],
["[17] Show rioolwaardes", "show_rioolwater"],
["[18] SIR model met leeftijdsgroepen","SIR_age_structured_streamlit"],
["[19] grafiek pos testen per leeftijdscat","grafiek pos testen per leeftijdscategorie streamlit"],
["[20] per provincie per leeftijd","perprovincieperleeftijd"],
["[21] kans om covid op te lopen","kans_om_covid_op_te_lopen"],
["[22] Data per gemeente", "vacc_inkomen_cases"] ,
["[23] VE Israel", "israel_zijlstra"],
["[24] Hosp/death NL", "cases_hospital_decased_NL"],
["[25] VE Nederland", "VE_nederland_"],
["[26] Scatterplots QoG OWID", "qog_owid"],
["[27] VE & CI calculations", "VE_CI_calculations"],
["[28] VE scenario calculator", "VE_scenario_calculator"],
["[29] VE vs inv. odds", "VE_vs_inv_odds"],
["[30] Fit to data Levitt", "fit_to_data_owid_levitt_streamlit_animated"],
["[31] Aerosol concentration in room by @hk_nien", "aerosol_in_room_streamlit"],
["[32] Compare two variants", "compare_two_variants"],
["[33] Scatterplot OWID", "scatterplots_owid"],
["[34] Playing with R0", "playing_with_R0"],
["[35] Calculate Se & Sp Rapidtest" , "calculate_se_sp_rapidtest_streamlit"],
["[36] Oversterfte gemeente" , "oversterfte_gemeente"],
["[37] Sterfte patronen" , "sterfte_2000_2024"],
["[38] Bayes Lines tools" , "bayes_lines_tools"],
["[39] Oversterfte (CBS Odata)" , "oversterfte_compleet"],
["[40] Bayes berekeningen IC ziekenh" , "bayes_prob_ic_hosp"],
["[41] Disabled by Long covid" , "disabled_by_longcovid"],
["[42] Oversterfte 5yrs groeps Eurostats" , "oversterfte_eurostats_maand"],
["[43] Doodsoorzaken Sankey" , "mortality_causes"],
["[44] Rioolwaarde vs ziekenhuis" , "rioolwater_vs_ziekenhuis"],
["[45] Rioolwaarde vs overleden CBS", "overledenen_rioolwaardes"],
["[46] Mortality yearly per capita", "mortality_yearly_per_capita"],
["[47] Deltavax", "deltavax"],
["[48] Verwachte sterfte", "verwachte_sterfte"],
["[49] Logistic regression", "logistic_regression"],
["[50] Calculate baselines (Poisson)", "calculate_baselines"],
["[51] AG table mortality", "agtable_mortality"],
["[52] Find baseline length", "find_baseline_length"],
["[53] Mortality/week/100k","mortality_weekly_per_age_per_capita"],
["[54] Herhaalprik","herhaalprik"],
["[55] Fit Mortality/causes death","fit_mortality"],
["[56] Bayes Mortality Vaccination","bayes_vaccination"],
["[57] Sterfte/rioolw./vaccins","correlatie_sterfte_rioolwater_vaccins"],
["[58] SIR model agent based","SIR_agent_based_vector"],
]
#query_params = st.experimental_get_query_params() # reading the choice from the URL..
# query_params = st.query_params["choice"]
try:
choice = int(st.query_params["choice"])
except:
choice = 0
# if "choice" in query_params else 0 # .. and make it the default value
if choice == 99: #sandbox
try:
module = dynamic_import("various_test_and_sandbox")
except Exception as e:
st.error(f"Module not found or error in the script\n")
st.warning(f"{e}")
st.stop()
try:
module.main()
except Exception as e:
st.error(f"Function 'main()' in module '{module}' not found or error in the script")
st.warning(f"{e}")
st.warning(traceback.format_exc())
st.stop()
st.stop()
menuchoicelist = [options[n][0] for n, l in enumerate(options)]
if choice !=0:
expanded = False
else:
expanded = True
with st.sidebar.expander('MENU: Choose a script | scroll down for options/parameters', expanded=expanded):
try:
menu_choice = st.radio(".",menuchoicelist, index=choice, label_visibility='hidden')
except:
st.error("ERROR. Choice not in menulist")
st.stop()
st.sidebar.markdown("<h1>- - - - - - - - - - - - - - - - - </h1>", unsafe_allow_html=True)
#st.experimental_set_query_params(choice=menuchoicelist.index(menu_choice)) # setting the choice in the URL
st.query_params.choice = menuchoicelist.index(menu_choice)
for n, l in enumerate(options):
if menu_choice == options[n][0]:
m = options[n][1].replace(" ","_") # I was too lazy to change it in the list
try:
module = dynamic_import(m)
except Exception as e:
st.error(f"Module '{m}' not found or error in the script\n")
st.warning(f"{e}")
st.warning(traceback.format_exc())
st.stop()
try:
module.main()
st.info(f"SCRIPT: https://github.com/rcsmit/COVIDcases/blob/main/{m}.py")
except Exception as e:
st.error(f"Function 'main()' in module '{m}' not found or error in the script")
st.warning(f"{e}")
st.warning(traceback.format_exc())
st.stop()
if __name__ == "__main__":
main()
show_info()