From f472479e0db51cb0895b0d8930a67fc0b012cb13 Mon Sep 17 00:00:00 2001 From: linozen Date: Tue, 31 Aug 2021 11:05:44 +0200 Subject: [PATCH] small formatiing changes; some optimisations --- explorer/civsoc.py | 91 ++++++++++++++++++++++++++++------------------ explorer/media.py | 50 +++++++++++++++---------- explorer/merged.py | 47 +++++++++++++++--------- 3 files changed, 114 insertions(+), 74 deletions(-) diff --git a/explorer/civsoc.py b/explorer/civsoc.py index 13620d5..93d2ece 100644 --- a/explorer/civsoc.py +++ b/explorer/civsoc.py @@ -1200,10 +1200,10 @@ def callback(): sections, index=sections.index(query_section), key="section", - on_change=callback + on_change=callback, ) -st.write(selected_section) +st.caption("__" + selected_section + "__ | Civil Society representatives") filters = { "country": st.sidebar.selectbox( @@ -1241,7 +1241,7 @@ def callback(): window.parent.document.querySelector('section.main').scrollTo(0, 0); """, - height=0 + height=0, ) st.markdown( @@ -1255,9 +1255,6 @@ def callback(): ############################################################################### -st.title("IOI Survey Data Explorer") -st.write("... of the responses given by __civil society organisation__ representatives") - if selected_section == "Overview": st.write("# Overview") @@ -1278,6 +1275,12 @@ def callback(): df[filter], values=country_counts, names=country_counts.index, + color=country_counts.index, + color_discrete_map={ + "Germany": px.colors.qualitative.Prism[5], + "France": px.colors.qualitative.Prism[1], + "United Kingdom": px.colors.qualitative.Prism[7], + }, ) ) @@ -1527,7 +1530,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -1560,7 +1563,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[CSfinance2other]`") @@ -1795,7 +1799,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -1828,7 +1832,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) campact2other_list = df[filter]["CScampact2other"].dropna().to_list() @@ -1927,7 +1932,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Agree completely", @@ -1960,7 +1965,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) CScampimpact2_list = df[filter]["CScampimpact2"].dropna().to_list() @@ -2036,7 +2042,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -2069,7 +2075,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) campact2other_list = df[filter]["CSadvocact2other"].dropna().to_list() @@ -2168,7 +2175,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Agree completely", @@ -2201,7 +2208,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) CSadvocimpact2_list = df[filter]["CSadvocimpact2"].dropna().to_list() @@ -2277,7 +2285,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -2310,7 +2318,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) campact2other_list = df[filter]["CSlitigateact2other"].dropna().to_list() @@ -2478,7 +2487,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Agree completely", @@ -2511,7 +2520,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) CSlitigateimpact2_list = df[filter]["CSlitigateimpact2"].dropna().to_list() @@ -2567,7 +2577,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2594,7 +2604,8 @@ def callback(): marker_color=px.colors.qualitative.Prism[10], ), ], - ) + ), + use_container_width=True, ) st.write( @@ -2662,7 +2673,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -2695,7 +2706,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) CSprotectops3other_list = df[filter]["CSprotectops3other"].dropna().to_list() @@ -2816,7 +2828,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2845,7 +2857,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) protectleg3other_list = df[filter]["CSprotectleg3other"].dropna().to_list() @@ -2940,7 +2953,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2969,7 +2982,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write( @@ -3003,7 +3017,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -3032,7 +3046,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) constraintinter5other_list = ( @@ -3087,7 +3102,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -3116,7 +3131,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) constraintinter6other_list = ( @@ -3163,7 +3179,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -3192,7 +3208,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) constraintself1other_list = df[filter]["CSconstraintself1other"].dropna().to_list() @@ -3267,7 +3284,7 @@ def callback(): CSattitude3_df = CSattitude3_df.drop_duplicates() st.plotly_chart( - generate_histogram( + render_histogram( df=CSattitude3_df, x="option", y="count", @@ -3279,7 +3296,8 @@ def callback(): "United Kingdom": px.colors.qualitative.Prism[7], }, labels={"count": "people who answered 'Yes'"}, - ) + ), + use_container_width=True, ) scoring = {1: 6, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1} @@ -3308,6 +3326,7 @@ def callback(): st.plotly_chart(render_ranking_plot("CSattitude6")) if selected_section == "Appendix": + st.write("# Appendix") st.write("## Raw data") diff --git a/explorer/media.py b/explorer/media.py index 0ba4a59..500a04c 100644 --- a/explorer/media.py +++ b/explorer/media.py @@ -1010,10 +1010,10 @@ def callback(): sections, index=sections.index(query_section), key="section", - on_change=callback + on_change=callback, ) -st.write(selected_section) +st.caption("__" + selected_section + "__ | Media representatives") filters = { "country": st.sidebar.selectbox( @@ -1051,7 +1051,7 @@ def callback(): window.parent.document.querySelector('section.main').scrollTo(0, 0); """, - height=0 + height=0, ) st.markdown( @@ -1065,9 +1065,6 @@ def callback(): ############################################################################### -st.title("IOI Survey Data Explorer") -st.write("... of the responses given by __media__ representatives") - if selected_section == "Overview": st.write("# Overview") @@ -1088,6 +1085,12 @@ def callback(): df[filter], values=country_counts, names=country_counts.index, + color=country_counts.index, + color_discrete_map={ + "Germany": px.colors.qualitative.Prism[5], + "France": px.colors.qualitative.Prism[1], + "United Kingdom": px.colors.qualitative.Prism[7], + }, ), use_container_width=True, ) @@ -2062,7 +2065,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -2095,7 +2098,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[MSprotectops3other]`") @@ -2210,7 +2214,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2239,7 +2243,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[MSprotectleg3other]`") @@ -2272,7 +2277,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2301,7 +2306,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[MSprotectleg4other]`") @@ -2653,7 +2659,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2682,7 +2688,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write( @@ -2716,7 +2723,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2745,7 +2752,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[MSconstraintinter5other]`") @@ -2794,7 +2802,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2823,7 +2831,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[MSconstraintinter6other]`") @@ -2872,7 +2881,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -2901,7 +2910,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[MSconstraintself1other]`") diff --git a/explorer/merged.py b/explorer/merged.py index 4d69fb9..9433b3b 100644 --- a/explorer/merged.py +++ b/explorer/merged.py @@ -928,7 +928,11 @@ def callback(): on_change=callback, ) -st.write(selected_section) +st.caption( + "__" + + selected_section + + "__ | Civil Society Organisation and Media representatives" +) filters = { "surveytype": st.sidebar.selectbox( @@ -983,11 +987,6 @@ def callback(): ############################################################################### -st.title("IOI Survey Data Explorer") -st.write( - "... of the responses given by __media__ and __civil society organisation__ representatives" -) - if selected_section == "Overview": st.write("# Overview") @@ -1018,6 +1017,12 @@ def callback(): df[filter], values=country_counts, names=country_counts.index, + color=country_counts.index, + color_discrete_map={ + "Germany": px.colors.qualitative.Prism[5], + "France": px.colors.qualitative.Prism[1], + "United Kingdom": px.colors.qualitative.Prism[7], + }, ), use_container_width=True, ) @@ -1419,7 +1424,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -1446,7 +1451,8 @@ def callback(): marker_color=px.colors.qualitative.Prism[10], ), ], - ) + ), + use_container_width=True, ) st.write( @@ -1515,7 +1521,7 @@ def callback(): continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Very important", @@ -1548,7 +1554,8 @@ def callback(): marker_color="#FFC300", ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[protectops3other]`") @@ -1668,7 +1675,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -1697,7 +1704,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[protectleg3other]`") @@ -1784,7 +1792,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -1813,7 +1821,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write( @@ -1845,7 +1854,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -1874,7 +1883,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[constraintinter5other]`") @@ -1921,7 +1931,7 @@ def callback(): else: continue st.plotly_chart( - generate_stacked_bar_chart( + render_stacked_bar_chart( data=[ go.Bar( name="Yes", @@ -1950,7 +1960,8 @@ def callback(): opacity=0.8, ), ], - ) + ), + use_container_width=True, ) st.write("### If you selected ‘other’, please specify `[constraintinter6other]`")