Summary
Hi, Iβm trying to build a web app that will parse and visualize heart rate data extracted from Apple Health.
I want to add in a slider where user can choose the date(s) to filter the chosen dates they would like to see their heart rate.
Steps to reproduce
Code snippet:
st. subheader('Upload Data')
file = st.file_uploader("Upload your Apple Health data file (.xml) here...", type=['xml'])
if file is not None:
tree = ET.parse(file)
root = tree.getroot()
attribute = []
startDate = []
endDate = []
value = []
sourceName = []
for element in root.xpath("//Record[(@type='HKQuantityTypeIdentifierHeartRate') and \
contains(@sourceName, 'Watch')]"):
attribute.append(element.get('type'))
startDate.append(element.get('startDate'))
endDate.append(element.get('endDate'))
value.append(element.get('value'))
heartrate = pd.DataFrame({'attribute': attribute,'startDate': startDate, 'endDate': endDate, 'value':value})
heartrate.value = pd.to_numeric(heartrate.value)
heartrate.startDate = pd.to_datetime(heartrate.startDate).dt.date
heartrate.endDate = pd.to_datetime(heartrate.endDate).dt.time
heartrate_new = heartrate.rename (columns={'value': 'BPM', 'startDate': 'Date','endDate': 'Time'})
def df_filter(message,df):
dates = df['Date'].unique().tolist()
dates_selection = st.slider('%s' % (message),
min_value = min(df['Date']),
max_value = max(df['Date']),
value =(min(df['Date']),max(df['Date'])))
mask = df['Date'].between(*dates_selection)
number_of_result = df[mask].shape[0]
filtered_df = st.markdown(f'*Available Results: {number_of_result}*')
return filtered_df
if __name__ == '__main__':
df = pd.DataFrame(heartrate_new)
st.title('Datetime Filter')
filtered_df = df_filter('Move sliders to filter dataframe',df)
st.title('Data Frame')
st.write(filtered_df)
st.markdown('Filtered Data Frame',filtered_df)
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
I would like to showcase a table (dataframe) after the date filter is applied
Actual behavior:
I would very much appreciate your help on solving this issue!