I am trying to download a csv report on my customers when a button is pressed in anvil. However, this error keeps popping up. It works if the table has no data, but when there is data then it simply will not download. Here is my error:
Warning: admin_reports.download_csv_revenue_click does not exist. Trying to set the 'click' event handler of self.download_csv_revenue from admin_reports.
ValueError: Shape of passed values is (1, 1), indices imply (1, 9)
Here is my code:
@anvil.server.callable
def download_data():
# Execute SQL query to fetch all data from the CUSTOMER_BOOKING_INFORMATION table
cursor.execute("SELECT * FROM CUSTOMER_BOOKING_INFORMATION ORDER BY UN_TICKET_CODE ASC")
# Fetch all rows returned by the query
values = cursor.fetchall()
# Define the column names for the DataFrame
col = [
'UN_TICKET_CODE',
'USERNAME',
'NO_ECONOMY',
'NO_PREMIUM_ECONOMY',
'NO_FIRST_CLASS',
'TOTAL_BOOKINGS',
'PRICE',
'DISCOUNT',
'TOTAL_COST']
# Create a DataFrame using the fetched values and column names
df = pd.DataFrame(values, columns=col)
# Retrieve the user's download folder path
download_folder = os.path.expanduser("~")
# Create the file path for the CSV file
file_path = os.path.join(download_folder, 'test.csv')
# Write the DataFrame to a CSV file at the specified file path
df.to_csv(file_path, index=False)
# Return the CSV file as an Anvil Media object, which enables downloading the file
return anvil.media.from_file(file_path)
I've tried to research the problem, but I cannot find an answer or I simply didn't look enough. I would love some help!