Skip to content

Commit

Permalink
update the virtual environment settings and the project dependencies … (
Browse files Browse the repository at this point in the history
#121)

* update the virtual environment settings and the project dependencies to their latest versions

* Removed the sleep to improve the performance and upadated YAML file

---------

Co-authored-by: iris LUO <[email protected]>
Co-authored-by: Aishwarya Nadimpally <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2024
1 parent 9e54cde commit 266d180
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 34 deletions.
10 changes: 3 additions & 7 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ channels:
- defaults
dependencies:
- ipykernel
- altair
- altair=5.3.*
- dash=2.16.*
- dash-bootstrap-components=1.5.*
- plotly=5.19.*
- r-base
- r-tidyverse
- r-shiny
- r-languageserver
- r-plotly
- pip
- pandas=2.2.*
- pandas=2.2.*
- pyarrow=15.0.*
- pip:
- dash-daq==0.5.*
- dash-vega-components==0.10.*
Expand Down
Binary file modified src/__pycache__/callbacks.cpython-312.pyc
Binary file not shown.
Binary file modified src/__pycache__/components.cpython-312.pyc
Binary file not shown.
Binary file modified src/__pycache__/data.cpython-312.pyc
Binary file not shown.
4 changes: 0 additions & 4 deletions src/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def update_city_dropdown(selected_province):
)
@memory.cache()
def update_bar_chart(province, cities, var1, var2):
import time
time.sleep(2)
# If no city is selected, return an empty figure with a message
if not cities:
return {
Expand Down Expand Up @@ -115,8 +113,6 @@ def update_bar_chart(province, cities, var1, var2):
)
@memory.cache()
def update_bar_chart(province, cities, var3):
import time
time.sleep(2)
# If no city is selected, return an empty figure with a message
if not cities:
return {
Expand Down
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ gunicorn==21.2.*
dash-vega-components==0.10.*
vega-datasets==0.9.*
joblib==1.4.*
pyarrow==15.0.*
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"duration": 2.0362932682037354, "input_args": {"province": "'British Columbia'", "cities": "['Abbotsford', 'Burnaby']", "var1": "'Price'", "var2": "'Median Family Income'"}, "time": 1713648653.495363}
Binary file not shown.

This file was deleted.

Binary file not shown.
70 changes: 48 additions & 22 deletions src/tmp/joblib/callbacks/update_bar_chart/func_code.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# first line: 110
# first line: 32
@callback(
Output('bar-graph-2', 'figure'),
Output('bar-graph-1', 'figure'),
[Input('province-dropdown', 'value'),
Input('city-dropdown', 'value'),
Input('variable3-dropdown', 'value')]
Input('variable1-dropdown', 'value'),
Input('variable2-dropdown', 'value')]
)
@memory.cache()
def update_bar_chart(province, cities, var3):
def update_bar_chart(province, cities, var1, var2):
import time
time.sleep(2)
# If no city is selected, return an empty figure with a message
Expand All @@ -25,27 +26,52 @@ def update_bar_chart(province, cities, var3):
df_filtered = df[(df['Province'] == province) & (df['City'].isin(cities))]

# Group the data by City and calculate the mean of the selected variables
df_count = df_filtered.groupby('City')[[var3]].value_counts().reset_index()
top_5_per_city = (df_count.sort_values(['City', 'count'], ascending=[True, False])
.groupby('City')
.head(5))
df_grouped = df_filtered.groupby('City')[[var1,var2]].mean()
df_grouped_samevar = df_filtered.groupby('City').agg({var1: 'mean'})

color_seq = ['#98BDFF', '#F3797E', '#8B1FB6', '#1FB69F' , '#D0116D', '#601FB6']
fig = make_subplots(specs=[[{"secondary_y": True}]])

fig = px.bar(
top_5_per_city,
y=var3,
x='count',
orientation='h',
color='City',
text=f"count",
color_discrete_sequence=color_seq)
if var1 == var2:
# If the two variables are the same, plot only one set of bars
fig.add_trace(go.Bar(
x=df_grouped_samevar.index,
y=df_grouped_samevar[var1],
text=df_grouped_samevar[var1], # Add the income values as text
textposition='auto', # Position the text automatically
texttemplate='%{text:.2s}',
name=f'{var1}',
marker_color='#F3797E'))
else:
# If the two variables are different, plot two sets of bars
fig.add_trace(go.Bar(
x=df_grouped.index,
y=df_grouped[var1],
text=df_grouped[var1], # Add the income values as text
textposition='auto', # Position the text automatically
texttemplate='%{text:.2s}',
name=f'{var1}',
marker_color='#F3797E',
offsetgroup=1),
secondary_y=False
)

# Add bar 2 for var 2
fig.add_trace(go.Bar(
x=df_grouped.index,
y=df_grouped[var2],
text=df_grouped[var2],
textposition='auto',
texttemplate='%{text:.2s}',
name=f'{var2}',
marker_color='#7978E9',
offsetgroup=2),
secondary_y=True,
)

# Update the layout of the bar chart
fig.update_layout(title_text=f'Most Common Types {var3} in Selected Cities',
xaxis_title='Count',
yaxis_title=f'{var3}',
barmode='group')
fig.update_traces(textposition='outside')
fig.update_layout(title_text=f'Comparison of {var1} and {var2}',
barmode='group')
fig.update_yaxes(title_text=f'{var1}', secondary_y=False)
fig.update_yaxes(title_text=f'{var2}', secondary_y=True)

return fig

0 comments on commit 266d180

Please sign in to comment.