Function 'handle_upload' is not returning variable (which is excel file that has been read by pd.read_excel) , instead it's returning "ClickEventArguments" object
def handle_upload(e: events.UploadEventArguments):
file_content = e.content.read()
file_xlsx = pd.read_excel(file_content)
return file_xlsx
def start_campaign(file_xlsx):
pd.set_option("display.max_rows", None)
pd.set_option("display.max_colwidth", None)
for column_name in file_xlsx.columns:
if "Email" in column_name:
for email in file_xlsx[column_name]:
generate_email_campaign(receiver=email,)
with ui.card().classes("absolute-center").style("margin: 0px 0px 0px 15px; border-radius: 8px; box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px; "):
with ui.stepper().props('vertical').classes('w-full') as stepper:
# with ui.step('Product Details'):
# prompt = ui.input('Tell us about your product', on_change=lambda e: e.value)
# with ui.stepper_navigation():
# ui.button('Next', on_click=stepper.next)
with ui.step('Upload Data'):
ui.label("Upload a valid Excel file (xlsx) to begin your campaign.")
ui.upload(on_upload=handle_upload, multiple=False).props('accept=.xlsx')
with ui.stepper_navigation():
ui.button('Start', on_click=start_campaign)
ui.button('Back', on_click=stepper.previous).props('flat')
ui.run()
When 'start_campaign' is passed to on_click button, the read excel is supposed to be passed into the function 'start_campaign' for further processing and execution.
The problem is probably that the
on_clickevent handler automatically passes event arguments to the callback,start_campaignin this case, if it expects an argument. Therefore the click event arguments are passed tostart_campaign, which expectsfile_xlsx.To fix it, the button should look something like this: