Processing data in memory on client side

Hey all,

since dataframes cannot be used on client side I am wondering what would be the best way to process data in memory on client side if you also want to filter and sort data like you would do it with a dataframe.

Thanks a lot for your help!

You can interact with dataframes using functions on the server, which are called using arguments sent by the client, and which return values to the client. Can you provide a more specific example of exactly what you’re trying to do?

Thank you so much for your answer! I am using some large datasets (>1,000 rows, multiple columns) that are the basis for plots. To analyze the data it is neccessary to filter and sort the data which can be done easily with a dataframe. Since the communication between client and server always needs some time and the server needs to fetch the data again as every server call starts a new session on the server I was hoping to find a similar construct as a dataframe that could handle the dataset on the client side.

That sounds like a great use case for Anvil’s data tables. Can you provide a minimal example with some data? You can post a clone of your code here for others to take a stab at.

Thank you! Well it is a quite simple table like:

Example Table

What needs to be done is for example based on user interaction in the frontend: filter the whole dataset based on column language=‘en’ or count>10. The result is the basis for a plotly graph.

Since users play around with the data a lot I wanted to avoid any backend or table communication since these operations always take time.

Nevertheless, either I am switching to anvil tables now or trying some funny experiments with multiple lists synched over list positions.

You’ll get the best performance for users playing around on the client if you pass back a list of dictionaries from the server. Then you can use normal Python list comprehensions and sorting to do the client-side filtering.

If you have a large amount of data, the time it takes for that initial server call to return the data might be prohibitive (even to the point of the server function timing out). In that case, you might think about using client readable views: Anvil Docs | Data Security

Thanks @jshaffstall !!! I think the dict and list option is the one I am going to try now!