Caveat: I’m only a few weeks into coding after doing nothing since basic on my spectrum 128 in the 80s, so I am going to say stupid things and hope that can be forgiven.
I have an active server uplink. It is successfully connected to the client side and running a search of the Have I Been Pwned API and returning a dataframe of breaches, which is being taken across as a dict to a repeating panel. This is all working brilliantly. It generates rows in my background table and deletes everything when a new call is made as intended.
The problem is:
Also on the server side I’m getting a total number of breaches from one column in the table and using it to create a simple print statement “this account features in x breaches.”
When I run the search in the Anvil app, I get my dataframe, it converts, and appears in the grid and the background table.
I want to use the print statement as a summary in a label above the grid but I cannot for the life of work out how to do it. I’ve been through all the tutorials, I’ve walked away and come back. I’ve tried sub-functions, classes, even tried creating a second dataframe and datatable but that just drags in rows from the first.
I really don’t understand what to do and need some help, or just to be told it’s not possible.
What I’ve tried and what’s not working:
Current Server Code:
@anvil.server.callable
def getsearchparams(name, email, username):
subjectid = name
account = email
username = username
def getbreach():
pwny = pypwned.pwned(pwned_key)
result = pwny.getAllBreachesForAccount(email=account)
return result
result = getbreach()
df = pd.DataFrame(result)
df['Breaches'] = 1
df
#print(df)
for d in df.to_dict(orient="records"):
app_tables.breaches.add_row(**d)
Total = (df['Breaches'].sum())
Score = lambda: print("This email account appears in", Total, "breaches.")
anvil.server.wait_forever()
Client Side:
def light_search_click(self, **event_args):
"""This method is called when the button is clicked"""
app_tables.breaches.delete_all_rows()
name = self.input_name.text
email = self.input_email.text
username = self.input_username.text
anvil.server.call('getsearchparams', name, email, username)
Notification("Search in Progress").show()
self.caseheading.text = ("Subject: " + self.input_name.text)
self.breachresult1.items = app_tables.breaches.search()
text = anvil.server.call(Score)
self.breachsummary.text = text
Really need some guidance, thank you.