# Import packages
from dash import Dash, html, dash_table, dcc, callback, Output, Input
import pandas as pd
import plotly.express as px
# Incorporate data
df = pd.read_csv('enrollment_by_department.csv')
# Initialize the app
app = Dash(__name__)
# App layout
app.layout = html.Div([
html.Div(children='GSU Enrollments'),
dcc.Dropdown(df["Department"], df["Department"][0], id='choose-dept'),
dash_table.DataTable(data=df.to_dict('records'), page_size=10),
dcc.Graph(figure={}, id='controls-and-graph')
])
# Add controls to build the interaction
@callback(
Output(component_id='controls-and-graph', component_property='figure'),
Input(component_id='choose-dept', component_property='value')
)
def update_graph(dept):
d = df[df["Department"] == dept]
d = d.T[1:]
d.columns = ['enroll']
d.index.name = 'semester'
d.reset_index(inplace=True)
fig = px.bar(d, x='semester', y='enroll')
return fig
# Run the app
if __name__ == '__main__':
app.run(debug=True)