I send file to jupyter and receive a dataframe as a output.
Dataframe might have different columns, so I want to be flexible here.
I created new table in Data tables with name “osago1”. No columns. Ticked “columns autocreate”.
And just in case provide permission to read and write to forms.
It shows python name for table: app_tables.osago1
When I try to use the following code on jupyter:
for d in final_df.to_dict(orient=“records”):
# d is now a dict of {columnname -> value} for this row
# We use Python’s **kwargs syntax to pass the whole dict as
# keyword arguments
app_tables.osago1.add_row(**d)
I get the following error:
AttributeError: No such app table: ‘osago1’
at /home/vs/anaconda3/lib/python3.7/site-packages/anvil/tables/init.py, line 20
Could you please help how to publish dataframe to a grid.
I’m just wondering if you are connecting to a different app accidentally (one without that table).
Is it possible for you to share a clone link of your app so we can take a look (do not share if there is sensitive data)? Click the in the IDE and follow the instructions if you are able to share a clone.
When I clone the app and try adding rows with a list of dicts, everything works as expected:
ds=[{'a': 1, 'b': 2}, {'a': 11, 'b': 21}, {'a': 11, 'b': 22}]
for d in ds:
app_tables.osago1.add_row(**d)
Anvil server output: Automatically creating column "a" (number)
Anvil server output:
Anvil server output: Automatically creating column "b" (number)
Anvil server output:
If you have not already double checked your uplink key, please do so (although I think you have already)
This is a different error than the original post and means you need to switch to a different Python runtime if you are importing Pandas in a server module. Try switching to the full Python 2.7 or Python 3.6 runtimes (see top right hand corner of the server modules).
#Anvil Uplink server definition
import anvil.media
import csv
import json
import anvil.tables
from anvil.tables import app_tables
@anvil.server.callable
def extract_xlsdata(file):
with anvil.media.TempFile(file) as filename:
#for d in final_df.to_dict(orient="records"):
# d is now a dict of {columnname -> value} for this row
# We use Python's **kwargs syntax to pass the whole dict as
# keyword arguments
# app_tables.osago1.add_row(**d)
ds=[{'a': 1, 'b': 2}, {'a': 11, 'b': 21}, {'a': 11, 'b': 22}]
for d in ds:
app_tables.osago1.add_row(**d)
return finalt
#Required, so the web app could call the function
anvil.server.wait_forever()
Still the same error:
AttributeError: No such app table: ‘osago1’ at /home/vs/anaconda3/lib/python3.7/site-packages/anvil/tables/init.py, line 20 called from , line 9 called from [Form1, line 19](javascript:void(0))
If everything is working, I am still left wondering if the original Uplink key was simply pointing to another app, or if the table name in the app was slightly different. That’s all I can think of.
Thanks a lot!
Yes, now it is adding data to table. In the original app: Uplink key was correct (it worked without access to the table) and table name was correct (I tried several table names and created new tables).
So, I guess the system decided not to mess with you
Btw, what is the fasted way to put this data table to grid, so I would not add columns names manually. Something similiar to df.head(10) in python.