Objective: Getting a pandas dataframe generated from server side data to a csv file to a media object to be able to download the csv file in the server module.
I am generating small dataframes of data based on a few parameters on the server module and after creating the data want the user to be able to download the csv files. I do not need to save the csv files as I can generate the data from the parameters and would merely waste memory.
My thought process is generate data, create df, save to csv local temp folder load csv file as media object and call download on button click.
I could generate the data save a csv and send a media object remotely but my goal is to do this using the server module server side as this code is small and fast.
Here is demo code of server module, after consulting all documention have exhausted options.
@anvil.server.callable
def make_data(**kwargs):
x_arr = np.array([[1,2,3]]) #placeholder data
X = pd.DataFrame(x_arr)
X.to_csv('/tmp/X.csv')
X_media = anvil.media.from_file('/tmp/X.csv', 'csv', 'X')
return X_media
In the Home class upon button click, am of course calling this function with download.
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
x_media =anvil.server.call("make_data")
download(x_media)
I am recieving from the server module
AttributeError: module âanvilâ has no attribute âmediaâ
Despite code being in documentation @
https://anvil.works/docs/media
Is there an equivilant updated module for this call? I could not find it.