However I am using a full path here as my csv file path, and after I run the function, it brings up an error and said there is no such file. Is this because of the full path I used? If I want to use relative path, then which directory should I start with?
Thanks in advance
It actually worked with /tmp/your_file.csv, However can you explain more in detail why do I need to put this here rather than a relative path?, also why not put ./tmp/your_file.csv instead?
The /tmp directory is on the Anvil servers. They let you store temporary files there (which, by the way, are not guaranteed to exist beyond the server call).
You could move the whole server side code to your own server using the uplink functionality and then you can use whatever path you like, but you are restricted to absolute path /tmp on the Anvil servers.
yes this is exactly what I did
In the server code, I have:
@anvil.server.callable
def make_data():
csv_1 = app_tables.csv_1.search()
dicts = [{'site':r['site'],
'actual_nw':r['actual_nw'],
'ea_model':r['ea_model'],
'ea_model_difference':r['ea_model_difference']}
for r in csv_1]
X = pd.DataFrame.from_dict(dicts)
X.to_csv("/tmp/X.csv")
X_media = anvil.media.from_file('/tmp/X.csv', 'csv', 'X')
return X_media
In the user part, I have:
def download_button_click(self, **event_args):
"""This method is called when the button is clicked"""
csv_1_url_media = anvil.server.call('make_data')
download(csv_1_url_media)
I know this is an old post, but I ran into it and the clone almost worked. I am sure anvil made an update. so for people in the future, this one line update gave me a .csv instead of a .txt: