What I’m trying to do:
Please see cloned app. I have two server functions called from the client side:
- tod_preprocess
- 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):
-
tod_preprocess:
return df_final.to_markdown(), dp_plans_all, unq_act, act_all_fun
-
yaml_process:
Beginning of function:
import anvil.media
@anvil.server.callable
def yaml_process(file):
#importing the yaml
yml_file = file
import ruamel.yamldef 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