How to run python function by clicking html button?

After many unsuccessful tries with flask (my question in Stackoverflow) ,I decided to take another direction, to use dash.

I was able to do some search online and I was able to find this_post which has almost everything I need for my API.

I am substituting the function “some_function” from the example with my function:

def transform(df):
     #count the number of columns in the data frame
    col=len(df.columns)
    if col>3:
    #Transform a matrix to a vector
        df=df.set_index(df.columns[0]).stack().reset_index()
        df[['Date','level_1']]=df[['Date','level_1']].astype(str)
        df['dtime']=df['Date']+' '+df['level_1']
        df['dtime'] = pd.to_datetime(df['dtime'])
        df=df.drop(['Date', 'level_1'], axis=1)
        df.columns=['KW','dtime']
        df=df[['dtime','KW']]
        df=df.sort_values(by='dtime',ascending=False)
        df.reset_index(inplace=True,drop=True)
    #df.index = pd.to_datetime(df[df.columns[[0,1]]].astype(str).apply('-'.join,1))
    else:
        df.columns =(['dtime','kW'])
        df['dtime'] = pd.to_datetime(df['dtime'])
        df['dtime'] = pd.to_datetime(df['dtime'])
#find the interval by substracting the second date from the first one
    a = df.loc[0, 'dtime']
    b = df.loc[1, 'dtime']
    c = a - b
    minutes = c.total_seconds() / 60
    d=int(minutes) #d can be only 15 ,30 or 60
    #This function will create new row to the time series anytime when it finds gaps and will fill it with NaN or leave it blank.
    #df.drop_duplicates(keep='first') keeps the first value of duplicates
    if d==15:
        df.drop_duplicates(keep='first',inplace=True)
        df= df.set_index('dtime').asfreq('-15T')
    elif d==30:
        df.drop_duplicates(keep='first',inplace=True)
        df= df.set_index('dtime').asfreq('-30T')
    elif d==60:
        df.drop_duplicates(keep='first',inplace=True)
        df= df.set_index('dtime').asfreq('-60T')
    else:
        None
    return df

The script runs fine, without any errors but the output is strange output. I am not sure what I am doing wrong.

In addition:

1.How to export the file in excel format

2.(from the example)Does the function (some_function) iterate through all of the sheets, if I import an excel file? I am asking this because I need to know if I have to create an iteration for my function(transform)