# INSTRUCTIONS: # 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu # 2. run in terminal with: streamlit run app.py # 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL # 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show # 5. use the URL from prior steps as intput into this simple browser import re import streamlit as st import altair as alt from vega_datasets import data import pandas as pd st.title('IS 445: Final Project Pt.2') st.header('Brie McCabe & Jacob Fieldman') #st.text("The URL for this app is: https://huggingface.co/spaces/445final/final2.moved") #st.markdown("check out this [link](%s)" % url) #st.text('Overall Future Edits: Figure out what to do with positions with 1 employee (if anything), Decide whether to use transportation or corrections data, Re-capitalize agency departments') #st.text('Chart A Future Edits: Order bars by mean YTD Gross, Make all position titles readable, add title') st.markdown("Below is a dashboard exploring all current state employees and their salaries. The dataset includes information like the agency, division, position title, and pay for all the current state employees. The first bar chart represents the average salary by department and is ranked with the agency with the highest average salary at the top and then the agency with the lowest average salary at the bottom.") st.markdown('This bar chart is interactive. When you hover an agency that interests you, you get a tooltip with the full name of the agency and the exact dollar amount of the average salary from that agency.') st.markdown("The second graph at the bottom of the screen is a scatter plot showing individual positions and the corresponding salaries. You can select an agency to investigate further by selecting the corresponding bar of the agency you would like to investigate. This will filter the scatter plot to just show information relating the agency that you have selected. The scatter plot shows the spread of salaries in that agency. With the tooltip on this scatterplot, you can see the individuals job title and the salary amount associated.") st.markdown("These graphs allow you to understand where state funding is going and the distribution of where money is going within different agencies throughout the state. The spending of the sate helps individuals understand what priorities the state government has and where their tax dollars are being spent.") st.markdown("Below is a link to more data that could help add context to this information. This dataset offers more information about state salaries from the year 2011-current. This dataset was too large for us originally but we think analyzing the changes of state investments over time will be interesting.") url = "https://data.illinois.gov/Government-and-Public-Employees/State-Employee-Pay-hired-after-1-1-2011/2ke2-x724/about_data" st.markdown("This is the link to our supplimental dataset [link](%s)" % url) #im just going to relaod the data frame in to clean up the text on the bottomo charts df_j = pd.read_csv('State_Employee_Pay.csv') df_jcopy = df_j.copy() df_jcopy['Period Pay Rate'] = df_jcopy['Period Pay Rate'].str.replace(",", "").astype(int) df_jcopy['YTD Gross'] = df_jcopy['YTD Gross'].str.replace(",", "").astype(int) df_jcopy = df_jcopy.dropna() df_jcopy = df_jcopy[df_jcopy['YTD Gross'] != 0] # df_jcopy['Agency'] = df_jcopy['Agency'].str.lower() # df_jcopy['Agency Division'] = df_jcopy['Agency Division'].str.lower() # df_jcopy['Employee Name'] = df_jcopy['Employee Name'].str.lower() # df_jcopy['Position Title'] = df_jcopy['Position Title'].str.lower() df_jcopy['Agency'] = df_jcopy['Agency'].str.replace(r'^(il |ill |illinois )', '', flags=re.IGNORECASE, regex=True) df_jcopy.columns = df_jcopy.columns.str.strip() alt.data_transformers.disable_max_rows() df_small=df_jcopy[['Agency','YTD Gross']].copy() select_bar = alt.selection_point( fields=["Agency"], on="click", clear="true" ) #summing the barchart but the human services and transit departments are so large you cannot click on the other agencies # bar_chart = ( # alt.Chart(df_small) # .mark_bar() # .encode( # y=alt.Y("Agency:N", sort="-x"), # x=alt.X("sum(YTD Gross):Q", title="Total Personale Expense"), # <-- take the mean # tooltip=[ # "Agency:N", # alt.Tooltip("mean(YTD Gross):Q", title="Avg YTD Gross", format="$,.0f") # ], # color=alt.condition(select_bar, alt.value("#4C78A8"), alt.value("#CCCCCC")) # ) # .add_params(select_bar) # .properties(width=500, height=800) # ) # bar_chart = ( # alt.Chart(df_small) # .mark_bar() # .encode( # y=alt.Y("Agency:N", sort="-x"), # x=alt.X("mean(YTD Gross):Q", title="Average Personale Expense"), # <-- take the mean # tooltip=[ # "Agency:N", # alt.Tooltip("mean(YTD Gross):Q", title="Avg YTD Gross", format="$,.0f") # ], # color=alt.condition(select_bar, alt.value("#4C78A8"), alt.value("#CCCCCC")) # ) # .add_params(select_bar) # .properties(width=500, height=800) # ) bar_chart = ( alt.Chart(df_jcopy) .mark_bar() .encode( y=alt.Y("Agency:N", sort="-x",title="Agency" ), x=alt.X("mean(YTD Gross):Q", axis=alt.Axis(labelLimit=0, title="Average Year to Date Gross Pay")), tooltip=[ "Agency:N", alt.Tooltip("mean(YTD Gross):Q", title="Avg YTD Gross", format="$,.00f") ], color=alt.condition(select_bar, alt.value("#4C78A8"), alt.value("#CCCCCC")) ) .add_params(select_bar) .properties(width=500, height=800, title="Average YTD Gross Pay per Agency") ) # box = ( # alt.Chart(df_small) # .mark_boxplot(size=40) # .encode( # x=alt.X("Agency:N", title=""), # y=alt.Y("YTD Gross:Q", title="Salary Distribution"), # opacity=alt.condition(select_bar,alt.value(1),alt.value(0)), # color=alt.value("#4C78A8") # ) # .properties(width=1000, height=800) # ) # hist = ( # alt.Chart(df_small) # .mark_bar(opacity=0.7) # .encode( # x=alt.X("YTD Gross:Q", bin=True, title="YTD Gross (binned)"), # y=alt.Y("count()", title="Count"), # color=alt.value("#4C78A8"), # tooltip=[alt.Tooltip("YTD Gross:Q",title="Range"),alt.Tooltip("count():Q",title="Count")] # ) # .transform_filter(select_bar) # .properties(width=400, height=300) # ) strip = ( alt.Chart(df_jcopy) .mark_circle(size=60, opacity=0.6) .encode( x=alt.X("YTD Gross:Q", title="Individual Employee YTD Gross Pay"), y=alt.Y("Agency:N", title=""), color=alt.Color("Agency:N",title='Agency'), tooltip=[ alt.Tooltip("Position Title:O"), alt.Tooltip("YTD Gross:Q", format="$,.0f") ] ) .transform_filter(select_bar) .transform_calculate( jitter="0.4 * (random() - 0.5)" ) .encode( y=alt.Y("jitter:Q", title="", axis=None) ) .properties(width=400, height=200) ) dashboard = bar_chart & strip dashboard