Passing Data between Server Callable Functions

What I’m trying to do:
Please see cloned app. I have two server functions called from the client side:

  1. tod_preprocess
  2. yaml_process

The first function returns a dataframe that I use to provide a visual display on the client side (i.e., rich text format “tod_table”).
I am also trying to return from this first function a couple of lists (e.g., a list called unq_act) that I need to run the second function, yaml_process. I am very new to Anvil and have been trying to read the docs and look through the forum but couldn’t find something close to what I wanted to achieve.

What I’ve tried and what’s not working:
When trying to run the second function, I obviously get the

NameError: name ‘unq_act’ is not defined

How I get around this? I appreciate all the help

Server Code
For brevity (each function is approx 500 lines long), I will only include the relevant peices of the code (end/returns of the first functions and beginning/end of second function):

  1. tod_preprocess:

     return df_final.to_markdown(), dp_plans_all, unq_act, act_all_fun
    
  2. yaml_process:
    Beginning of function:

import anvil.media

@anvil.server.callable

def yaml_process(file):
#importing the yaml
yml_file = file
import ruamel.yaml

def unique_lists(lst_of_lsts): #defining unique lists for unq_act so that we iterate over them and create plans.
    unique = set()
    result = []
    for lst in lst_of_lsts:
        if tuple(lst) not in unique:
            unique.add(tuple(lst))
            result.append(lst)
    return result

end of the function:

    # Seek to the beginning of the file
    file.seek(0)
    # Overwrite the file with the updated documents
    yaml.dump_all(data, file)
    file.write("...\n")
    # Close the file
    #file.truncate()
    #return the file
    return file

Clone link:
share a copy of your app

Your clone link doesn’t have any server code that can help track the issue

I edited the question to include some of the server code. Hope it clears things up a bit.

I think I understood the problem. You are returning multiple variables from the server side but not really storing them on the client. Just replace with this piece of code.

tod_df, dp_plans_all, unq_act, act_all_fun = anvil.server.call('tod_preprocess', file)

Thank you, I went ahead and did this but now I get an issue with unpacking. The first function should return 4 variables, and I am assigning (on the client side) them also to 4 variables. However I end up with:

ValueError: too many values to unpack (expected 4)

Not sure why.

Print out the return from the server function to see what’s actually there.

Thanks, I was able to resolve the previous issue. However, I am stil stuck on how to pass the returned variables from the first callable function to the second one. I’d appreciate any pointers.