Simple issue of outputting a pandas dataframe generated in server side to client side using data grid (or any other suggestion

I have coded a function server side which will generate a pandas Dataframe.
I just want this visible in a tabular format clientside when they click a button.

Server side code snippet:
This linked to run button:
if Pb>=Pmax:
df_final[‘T’] = df_samples_pred[‘T’].values
df_final[‘api’] = df_samples_pred[‘api’].values
df_final[‘gasgrav’] = df_samples_pred[‘gasgrav’].values
df_final[‘pres’] = df_samples_pred[‘pres’].values
df_final[‘Rs’] = df_samples_pred[‘rs_calc’].values
df_final[‘Bo’] = df_samples_pred[‘bo_calc’].values
df_final[‘Deadoil Viscosity’] = df_samples_pred[‘visdead’].values
df_final[‘Live Oil Viscosity’] = df_samples_pred[‘vislive’].values
print(df_final) ## I want to output this to the client

else:
df_below=pd.DataFrame()
df_above=df_samples_pred_1.iloc[:-1]
df_below[‘T’] = df_samples_pred[‘T’].values
df_below[‘api’] = df_samples_pred[‘api’].values
df_below[‘gasgrav’] = df_samples_pred[‘gasgrav’].values
df_below[‘pres’] = df_samples_pred[‘pres’].values
df_below[‘Rs’] = df_samples_pred[‘rs_calc’].values
df_below[‘Bo’] = df_samples_pred[‘bo_calc’].values
df_below[‘Dead Oil Viscosity’] = df_samples_pred[‘visdead’].values
df_below[‘Live Oil Viscosity’] = df_samples_pred[‘vislive’].values
df_final=pd.concat([df_above, df_below],ignore_index=True)
print(df_final) ## I want to output this to the client

Client side:
A table to show that dataframe. ( I have added a grid structure

Most of the time we would point you to datagrids in the docs, but I have seen questions similar to this answered by using pandas to output to richtext using the .to_markdown() method of the data frame and then having it sent to a richtext component.

Like here:

3 Likes

Thanks. I got it to work with rich text and to_markdown perfectly.

1 Like