Data table not being recognized by Uplink server code

I’m trying to use the method in the documentation to use server code to write data to a data table, but I keep getting the error AttributeError: No such app table: 'dataframe'. I definitely do have an app table of that name and it is recognized in my Form1, but it seems that my server can’t access it.

Using these imports:

from ._anvil_designer import Form1Template
from anvil import *
import anvil.media
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import anvil.server

This is my Form1 code for calling the server function:

  def file_loader_1_change(self, file, **event_args):
    """This method is called when a new file is loaded into this FileLoader"""
    #this stores the data in the anvil data table
    anvil.server.call('store_data', file)

This is the ‘store_data’ function called in the previous code:

import pandas as pd
import anvil.media
import anvil.tables as tables
from anvil.tables import app_tables

@anvil.server.callable
def store_data(file):
  app_tables.dataframe.delete_all_rows()
  with anvil.media.TempFile(file) as f:
    df = pd.read_csv(f)
    for d in df.to_dict(orient="records"):
      app_tables.dataframe.add_row(**d)

Can you share a clone link? I don’t see anything that looks wrong in your code, so being able to see the rest of the app would help.

Sure, here is the clone link

https://anvil.works/build#clone:W4S2YO3XG6UNFSKY=U2UZHBT5VNKJGANIBOU3UCR5

I’m not quite sure what happened, but the clone has no server modules and your dataframe table has no fields.

I’m using Uplink to run code from a Google Colab notebook, so I’m not using server modules. The idea is to store the data in the file uploaded by the file loader so I can run it through a machine learning model after giving the user a chance to select which columns to include. So the initial data table is empty. I thought that checking the “Auto-create missing columns” option would let me import the data from a file using the method in the documentation. Can I not write new data to a table if I’m using Uplink?

You should be able to use data tables through uplink as far as I know, but I’m not an uplink user, so can’t advise you there. You might change the title to include Uplink, to catch the attention of the folks who know about working in that environment.

1 Like

As a possible workaround, do you know if I could just store the TempFile media object as a variable or attribute to pass to a second function within Anvil?

You might check the security settings on the table, vs. those used by your Uplink. E.g., if your Uplink program is connecting with Server-level privileges, but the table is set to deny Servers any access…

Thanks! The error was actually that my FORM didn’t have access. It’s now writing properly. Only problem now is that this just seems to write way too slow for using large data sets, so even though this issue is solved, looks like I’ll need to figure something else out. That’s for a different forum post though, I think.