def main(): st.title("Data") date = datetime.today() df = None load_state = st.text('Loading data......') while True: try: df = load_data(fetch_url(date)) except Exception as e: date = date - timedelta(days=1) continue break load_state.text("Loading data......done!") if st.checkbox("Show raw data"): st.subheader('Raw data') st.write(df) st.subheader("The numbers so far") st.markdown("* There are **{}** countries that have been affected by the COVID-19 virus.".format(len(df["Country_Region"].unique()))) st.markdown("* The virus has affected **{:.2f}M** people and caused the death of **{:.2f}K**.".format(df["Confirmed"].sum()/1000000, df["Deaths"].sum()/1000)) h_confirmed = df.groupby("Country_Region").agg({"Confirmed": "sum"}).nlargest(1,"Confirmed") st.markdown("* **{}** has the largest number of confirmed cases with **{:.2f}M** confirmed cases.".format(h_confirmed.index.values[0], h_confirmed["Confirmed"].values[0]/1000000)) h_deaths = df.groupby("Country_Region").agg({"Deaths": "sum"}).nlargest(1,"Deaths") st.markdown("* **{}** has the largest number of deaths with **{:.2f}K** deaths.".format(h_deaths.index.values[0], h_deaths["Deaths"].values[0]/1000)) h_recovered = df.groupby("Country_Region").agg({"Recovered": "sum"}).nlargest(1,"Recovered") st.markdown("* **{}** has the largest number of recoveries with **{:.2f}M** recovered.".format(h_recovered.index.values[0], h_recovered["Recovered"].values[0]/1000000))
def main(): pio.templates.default = "plotly_dark" date = datetime.today() df = None while True: try: df = load_data(fetch_url(date)) except Exception as e: date = date - timedelta(days=1) continue break time_series_dict = load_time_series() granularity = st.sidebar.selectbox("Granularity", ["Worldwide", "Country"]) if granularity == "Country": country = st.sidebar.selectbox("country", df["Country_Region"].unique()) st.title(country) graph_type = st.selectbox( "Choose visualization", ["Total Count", "Timeline", "Province/State"]) if graph_type == "Total Count": st.subheader("One day change") load_day_change(time_series_dict, time_series_dict.keys(), granularity, country=country) fig = plot_snapshot_numbers(df, px.colors.qualitative.D3, date.date(), country) st.plotly_chart(fig) elif graph_type == "Timeline": feature = st.selectbox("Select one", ["Confirmed", "Deaths", "Recovered"]) fig, _ = plot_timeline(time_series_dict[feature], feature, country=country) st.plotly_chart(fig) elif graph_type == "Province/State": fig = plot_province(df, country) if fig is not None: fig_drilled = None flag = st.checkbox("Summary (click and scroll)") st.subheader("Hover Map") st.plotly_chart(fig) if flag: if country == "US": fig_drilled = plot_province_drilled( load_data(fetch_url(date, country="US")), country) else: fig_drilled = plot_province_drilled(df, country) if fig_drilled is not None: st.subheader("Summary") st.plotly_chart(fig_drilled) else: # TODO(Sayar): Add values for deltas st.title("Worldwide") st.write("\n") st.info("Data updated as on {}".format( date.date().strftime("%d %B, %Y"))) graph_type = st.sidebar.selectbox( "Choose visualization", ["Total Count", "Top affected/recovered", "Timeline"]) if graph_type == "Total Count": st.subheader("One day change") load_day_change(time_series_dict, time_series_dict.keys(), granularity) fig = plot_snapshot_numbers(df, px.colors.qualitative.D3, date.date()) st.plotly_chart(fig) elif graph_type == "Top affected/recovered": fig = plot_top_countries(df, px.colors.qualitative.D3, date.date()) st.plotly_chart(fig) elif graph_type == "Timeline": feature = st.selectbox("Select one", ["Confirmed", "Deaths", "Recovered"]) fig, _ = plot_timeline(time_series_dict[feature], feature) st.plotly_chart(fig)