I am relatively new to Anvil and am still trying to wrap my head around building applications
that use a server (I usually just run my code in an IDE), so I appreciate the patience and help.
What I’m trying to do:
I want to use the client as a bridge to pass data between two server-callable functions. I have two server functions that I am calling from the client side:
- ‘tod_preprocess’: This function returns three variables (tod_df, dp_plans_all_ser, unq_act_ser) as shown in the cloned app. I am returning these variables since some of them will be needed for the second server-callable function, ‘yaml_process’, to be executed.
- ‘yaml_process’
As you can see from the cloned app, I am correctly assigning the returns to variables. However, I get a NameError:
NameError: name 'unq_act_ser' is not defined
Here is applicable part of my client-side code:
def file_loader_1_change(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”“”
tod_df, dp_plans_all_ser, unq_act_ser = anvil.server.call(‘tod_preprocess’, file)
self.tod_table.content = tod_df # displaying the final dataframedef file_loader_2_change(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”“”
yaml_processed = anvil.server.call(‘yaml_process’, file, unq_act_ser)
anvil.media.download(yaml_processed)
And this is a portion of the server-function that I have an issue with (it is a couple hundred lines so I am only including the applicable portion), yaml_process:
import anvil.media
@anvil.server.callable
def yaml_process(file, unq_act_ser):
unq_act_deser = json.loads(unq_act_ser)
#importing the yaml
yml_file = file
import ruamel.yamlBlockquote
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)
Clone link:
share a copy of your app