James McCool commited on
Commit
c9d235d
·
1 Parent(s): d581c52

Remove PDF export functionality from app.py and update requirements.txt to reflect changes. The `convert_df_to_pdf` function has been deleted, along with related download options for PDF. The requirements.txt file has been updated to remove the reportlab dependency, streamlining the application for CSV exports only.

Browse files
Files changed (2) hide show
  1. app.py +4 -63
  2. requirements.txt +1 -2
app.py CHANGED
@@ -9,10 +9,6 @@ import numpy as np
9
  import pandas as pd
10
  import streamlit as st
11
  import gspread
12
- from reportlab.lib import colors
13
- from reportlab.lib.pagesizes import letter, landscape
14
- from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
15
- from io import BytesIO
16
 
17
  @st.cache_resource
18
  def init_conn():
@@ -101,52 +97,6 @@ def init_baselines():
101
  def convert_df_to_csv(df):
102
  return df.to_csv().encode('utf-8')
103
 
104
- def convert_df_to_pdf(df):
105
- try:
106
- # Create a buffer to receive PDF data
107
- buffer = BytesIO()
108
-
109
- # Create the PDF object using the buffer as its "file"
110
- doc = SimpleDocTemplate(buffer, pagesize=landscape(letter))
111
-
112
- # Convert DataFrame to a list of lists for the table
113
- data = [df.columns.tolist()] + df.values.tolist()
114
-
115
- # Create the table
116
- table = Table(data)
117
-
118
- # Add style to the table
119
- style = TableStyle([
120
- ('BACKGROUND', (0, 0), (-1, 0), colors.grey),
121
- ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
122
- ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
123
- ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
124
- ('FONTSIZE', (0, 0), (-1, 0), 10),
125
- ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
126
- ('BACKGROUND', (0, 1), (-1, -1), colors.white),
127
- ('TEXTCOLOR', (0, 1), (-1, -1), colors.black),
128
- ('FONTNAME', (0, 1), (-1, -1), 'Helvetica'),
129
- ('FONTSIZE', (0, 1), (-1, -1), 8),
130
- ('GRID', (0, 0), (-1, -1), 1, colors.black),
131
- ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
132
- ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
133
- ])
134
- table.setStyle(style)
135
-
136
- # Build the PDF
137
- elements = [table]
138
- doc.build(elements)
139
-
140
- # Get the value of the BytesIO buffer
141
- pdf = buffer.getvalue()
142
- buffer.close()
143
-
144
- return pdf
145
-
146
- except Exception as e:
147
- st.error(f"Error generating PDF: {str(e)}")
148
- return None
149
-
150
  matchups, overall_ms, team_frame, team_list, team_dict = init_baselines()
151
 
152
  col1, col2 = st.columns([1, 9])
@@ -172,19 +122,10 @@ with col2:
172
  display_parsed = display_table[display_table['Line'].str.contains('|'.join(team_split))]
173
  display_parsed = display_parsed.set_index('Line')
174
  st.dataframe(display_parsed.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), height=500, use_container_width = True)
175
- download_var = st.selectbox('What download would you like?', options = ['CSV', 'PDF'], key='download_var')
176
- if st.button('Download'):
177
- if download_var == 'CSV':
178
- st.download_button(
179
- label="Export Marketshares (CSV)",
180
  data=convert_df_to_csv(display_table),
181
  file_name='Marketshares_export.csv',
182
  mime='text/csv',
183
- )
184
- elif download_var == 'PDF':
185
- st.download_button(
186
- label="Export Marketshares (PDF)",
187
- data=convert_df_to_pdf(display_table),
188
- file_name='Marketshares_export.pdf',
189
- mime='application/pdf',
190
- )
 
9
  import pandas as pd
10
  import streamlit as st
11
  import gspread
 
 
 
 
12
 
13
  @st.cache_resource
14
  def init_conn():
 
97
  def convert_df_to_csv(df):
98
  return df.to_csv().encode('utf-8')
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  matchups, overall_ms, team_frame, team_list, team_dict = init_baselines()
101
 
102
  col1, col2 = st.columns([1, 9])
 
122
  display_parsed = display_table[display_table['Line'].str.contains('|'.join(team_split))]
123
  display_parsed = display_parsed.set_index('Line')
124
  st.dataframe(display_parsed.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), height=500, use_container_width = True)
125
+
126
+ st.download_button(
127
+ label="Export Marketshares (CSV)",
 
 
128
  data=convert_df_to_csv(display_table),
129
  file_name='Marketshares_export.csv',
130
  mime='text/csv',
131
+ )
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -5,5 +5,4 @@ matplotlib
5
  pulp
6
  docker
7
  plotly
8
- scipy
9
- reportlab
 
5
  pulp
6
  docker
7
  plotly
8
+ scipy