Skip to content

Commit a09197f

Browse files
authored
Merge pull request #400 from A-Akhil/main
Issue #382 fixed StreamlitDuplicateElementId
2 parents 0597a3a + 2b3fb35 commit a09197f

File tree

6 files changed

+48
-21
lines changed

6 files changed

+48
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
catboost_info/
2+
venv/
3+
.venv/
24
streamlit\__pycache__
-609 Bytes
Binary file not shown.
-35 Bytes
Binary file not shown.

streamlit/functions.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020
results = pd.read_csv("https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/results.csv")
2121

2222

23+
# Load the data from local CSV files
24+
# data = pd.read_csv('df2020.csv')
25+
# df2018 = pd.read_csv('df2018.csv')
26+
# full_data2018 = pd.read_csv('survey_results_sample_2018.csv')
27+
# full_data2019 = pd.read_csv('survey_results_sample_2019.csv')
28+
# full_df2020 = pd.read_csv('survey_results_sample_2020.csv')
29+
# df2019 = pd.read_csv('df2019.csv')
30+
31+
# # Filter the 2020 data
32+
# df2020 = data[(data['SalaryUSD'] < 200000)]
33+
34+
# # Load results for job satisfaction from the local file
35+
# results = pd.read_csv("results.csv")
36+
37+
2338
#######################################
2439
# VISUALISATION STARTS
2540
#######################################
@@ -35,7 +50,7 @@ def plot_boxplot(data, x, y, title):
3550

3651
#########################################################################
3752

38-
def plot_bar_plotly(df, column_name, top_n=10, height=450, width=700):
53+
def plot_bar_plotly(df, column_name, top_n=10, height=450, width=700, key=None):
3954
df_counts = df[column_name].value_counts().head(top_n).reset_index()
4055
df_counts.columns = [column_name, 'Count']
4156

@@ -46,7 +61,7 @@ def plot_bar_plotly(df, column_name, top_n=10, height=450, width=700):
4661
fig.update_layout(xaxis_title=column_name, yaxis_title='Number of Developers')
4762
fig.update_layout(height=height, width=width)
4863

49-
return st.plotly_chart(fig)
64+
return st.plotly_chart(fig, key=key)
5065

5166

5267
def plot_pie_plotly(df, column_name,top_n=10, height=400, width=400 ):

streamlit/home.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@ def load_data(url):
1616
return pd.read_csv(url)
1717

1818
# Loading data files from the 'streamlit' directory
19-
df = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2020.csv')
20-
df2018 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2018.csv')
21-
full_data2018 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/survey_results_sample_2018.csv')
22-
full_data2019 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/survey_results_sample_2019.csv')
23-
full_df2020 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/survey_results_sample_2020.csv')
24-
df2019 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2019.csv')
25-
df2021 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2021.csv')
26-
df2022 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2022.csv')
19+
# df = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2020.csv')
20+
# df2018 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2018.csv')
21+
# full_data2018 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/survey_results_sample_2018.csv')
22+
# full_data2019 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/survey_results_sample_2019.csv')
23+
# full_df2020 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/survey_results_sample_2020.csv')
24+
# df2019 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2019.csv')
25+
# df2021 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2021.csv')
26+
# df2022 = load_data('https://raw.githubusercontent.com/Recode-Hive/Stackoverflow-Analysis/main/streamlit/df2022.csv')
27+
28+
df = load_data('df2020.csv')
29+
df2018 = load_data('df2018.csv')
30+
full_data2018 = load_data('survey_results_sample_2018.csv')
31+
full_data2019 = load_data('survey_results_sample_2019.csv')
32+
full_df2020 = load_data('survey_results_sample_2020.csv')
33+
df2019 = load_data('df2019.csv')
34+
df2021 = load_data('df2021.csv')
35+
df2022 = load_data('df2022.csv')
36+
2737

2838
# Filter the 2020 dataframe
2939
df2020 = df[df['SalaryUSD'] < 200000]
@@ -136,7 +146,7 @@ def plot_value_counts(column_name):
136146

137147
if year == '2018':
138148
main.main_analysis(df2018)
139-
main.main_analysis_2(df2018)
149+
main.main_analysis_2(df2018, year)
140150

141151
visual, analysis = st.columns((3, 1))
142152
with visual:
@@ -209,7 +219,7 @@ def plot_value_counts(column_name):
209219

210220
elif year == '2019':
211221
main.main_analysis(df2019)
212-
main.main_analysis_2(df2019)
222+
main.main_analysis_2(df2019, year)
213223

214224
visual, analysis = st.columns((3, 1))
215225
with visual:
@@ -228,7 +238,7 @@ def plot_value_counts(column_name):
228238

229239
elif year == '2020':
230240
main.main_analysis(df2020)
231-
main.main_analysis_2(df2020)
241+
main.main_analysis_2(df2020, year)
232242

233243
visual, analysis = st.columns((3, 1))
234244
with visual:
@@ -247,7 +257,7 @@ def plot_value_counts(column_name):
247257

248258
elif year == '2021':
249259
main.main_analysis(df2021)
250-
main.common_analysis_2021_2022(df2021)
260+
main.common_analysis_2021_2022(df2021, year)
251261
visual, analysis = st.columns((3, 1))
252262
with visual:
253263
fig = func.plot_valuecounts_plotly(df2021,'NEWStuck')
@@ -281,7 +291,7 @@ def plot_value_counts(column_name):
281291

282292
else:
283293
main.main_analysis(df2022)
284-
main.common_analysis_2021_2022(df2022)
294+
main.common_analysis_2021_2022(df2022, year)
285295

286296
fig = func.compare_language_columns_and_plot(df2022, 'OpSysPersonal use', 'OpSysProfessional use')
287297

streamlit/main_analysis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def main_analysis(df):
103103

104104
with visual:
105105
st.title("Ethnicity VS Participation")
106-
ff.plot_bar_plotly(df, 'Ethnicity')
106+
ff.plot_bar_plotly(df, 'Ethnicity', key='ethnicity_plot')
107107

108108
with analysis:
109109
Ethnicity_text = """
@@ -176,7 +176,7 @@ def main_analysis(df):
176176
if ds is not None:
177177
with visual:
178178
st.title("Country Wise Data Scientists Participation")
179-
ff.plot_bar_plotly(ds, "Country")
179+
ff.plot_bar_plotly(ds, "Country", key='country_plot')
180180

181181
with analysis:
182182
data_scientist_participation_text = """
@@ -196,7 +196,7 @@ def main_analysis(df):
196196
##### To Speed Up the Web Page, Main Analysis is divided into 2 ######
197197

198198

199-
def main_analysis_2(df):
199+
def main_analysis_2(df, year):
200200
visual2, analysis2 = st.columns((3,1))
201201

202202
if df is df2019:
@@ -262,7 +262,8 @@ def main_analysis_2(df):
262262
if ds is not None:
263263
with visual2:
264264
st.title("Country Wise Data Scientists Participation")
265-
ff.plot_bar_plotly(ds, "Country")
265+
# Use the year parameter instead of year_variable
266+
ff.plot_bar_plotly(ds, "Country", key=f'country_plot_{year}')
266267

267268
with analysis2:
268269
data_scientist_participation_text = """
@@ -368,7 +369,7 @@ def common_analysis_2021_2022(df):
368369
st.markdown(employment_text, unsafe_allow_html=True)
369370

370371
with visual3:
371-
ff.plot_bar_plotly(df, 'DevType', top_n=10, height=500, width=1000)
372+
ff.plot_bar_plotly(df, 'DevType', top_n=10, height=500, width=1000, key=f'devtype_plot_{year_variable}')
372373

373374
with analysis3:
374375
devtype_text = """
@@ -429,4 +430,3 @@ def common_analysis_2021_2022(df):
429430
</div>
430431
"""
431432
st.markdown(webframe_text, unsafe_allow_html=True)
432-

0 commit comments

Comments
 (0)