Extracting data from server and filter extracted based on widget inputs

Hello,
I am currently working on a dashboard where the user is able to

  1. Select the desired date range
  2. Use the selected date range to extract data from a remote server
  3. Filter that extracted dataset as desired based on chained widgets where one filter input alters the other filter options.

I am using param.Parameterized and have been able to accomplish task 1) and 2). To avoid having to re-extract data from the server each time a new filter I have tried to separate param.depends functions for the initial dataset extraction from the filtering of the extracted dataset. However, I can’t seem to figure out how to:

  1. Store the initially extracted dataset to avoid access the server over and over
  2. Apply chained filtering widgets to the initially extract dataset to produce the desired dataset without having to access the server every time a filter input changes.

Here is what I have so far:

Step 1

import param
DATE_BOUNDS = (dt.date(1900, 1, 1), dt.datetime.now().date())
class Hawkin_API(param.Parameterized): 
    start_date = param.Date(date.today()+ timedelta(days=-4), bounds=DATE_BOUNDS)
    end_date = param.Date(date.today(), bounds=DATE_BOUNDS)

Dataset Filters

athlete_select = param.ObjectSelector(objects = test_type)
test_select = param.ObjectSelector()

Display Dataset

  sample_df = param.DataFrame(doc="""
  The current dataframe of samples.""")

Access server based on selected date range

  generate_sample_df = param.Action(lambda self: self.update_sample_df(), doc="""
  An action callback which will update the sample_df.""")
def __init__(self, **params):
    super().__init__(**params)
    self.update_sample_df()

Step 2: Pull Dataset from server

@pn.depends(‘start_date’,‘end_date’)

def update_sample_df(self, event=None):
    response_get_test = requests.request("GET", url_asu_from_to, 
                                         headers=header_get_test, data = payload_get_test)

    tests = response_get_test.json()
    data = json_normalize(tests['data'])
    data[['test_type','tags']] = data['testType.name'].str.split('-',1,expand=True)
    athlete_names = data['athlete.name'].unique().tolist()

Update Dataframe and return Data

    self.sample_df=pd.DataFrame(data[['timestamp','athlete.name','test_type','tags']])
    self.param['athlete_select'].objects = athlete_names

Initial filter and display of altered dataset

@param.depends('athlete_select', watch=True)
def _update_countries(self):
    tests = self.sample_df[(self.sample_df['athlete.name'].isin(self.athletes))]['segment'].unique().tolist()
    self.param['test_select'].objects = tests
    filter_data = self.sample_df[(self.sample_df['athlete.name'].isin(self.athletes))]['segment'].unique().tolist()
    self.sample_df = pd.DataFrame(filter_data[['timestamp','athlete.name','test_type','tags']])

serversapi = Server_API()

I guess I’m not following completely. What exactly is causing you trouble? Could you not store the unfiltered dataset on some class variable and then whenever athlete_select changes you would simply filter on that unfiltered dataset? As far as I can tell your problem is simply that you are overriding the unfiltered data with the filtered data and then can’t go back and are basically forced to reload.