Skip to content

Commit

Permalink
Merge pull request #286 from MannLabs/fix_analysis_results
Browse files Browse the repository at this point in the history
FIX: used to try to show a dataframe as a plot, broke if two analyses…
  • Loading branch information
boopthesnoot authored Jun 3, 2024
2 parents bc0c726 + fcf0ed7 commit 9e0556a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion alphastats/gui/pages/04_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def select_analysis():

plot_to_display = False
df_to_display = False
method_plot = None

with c1:

Expand Down Expand Up @@ -196,7 +197,7 @@ def select_analysis():
with col3:
download_preprocessing_info(method_plot)

elif analysis_result is not None and df_to_display:
elif analysis_result is not None and df_to_display and method_plot:
col1, col2, col3 = st.columns([1, 1, 1])

with col1:
Expand Down
27 changes: 15 additions & 12 deletions alphastats/gui/pages/06_Results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def display_plotly_figure(plot):
st.plotly_chart(plot)


def save_plotly(plot, format):
def save_plotly(plot, name, format):
# Create an in-memory buffer
buffer = io.BytesIO()
# Save the figure as a pdf to the buffer
plot[1].write_image(file=buffer, format=format)
plot.write_image(file=buffer, format=format)
st.download_button(
label="Download as " + format, data=buffer, file_name=plot[0] + "." + format
label="Download as " + format, data=buffer, file_name=name + "." + format
)


Expand All @@ -27,10 +27,10 @@ def convert_df(df, user_session_id=st.session_state.user_session_id):
return df.to_csv().encode("utf-8")


def download_preprocessing_info(plot, count):
preprocesing_dict = plot[1].preprocessing
def download_preprocessing_info(plot, name, count):
preprocesing_dict = plot.preprocessing
df = pd.DataFrame(preprocesing_dict.items())
filename = "plot" + plot[0] + "preprocessing_info.csv"
filename = "plot" + name + "preprocessing_info.csv"
csv = convert_df(df)
st.download_button(
"Download DataSet Info as .csv",
Expand All @@ -50,21 +50,24 @@ def download_preprocessing_info(plot, count):
count = str(count)

st.markdown("\n\n")
st.write(plot[0])
name = plot[0]
plot = plot[1]
if name == "ttest":
plot = plot.plot
st.write(name)

display_plotly_figure(plot[1])
display_plotly_figure(plot)

col1, col2, col3 = st.columns([1, 1, 1])

with col1:
save_plotly(plot, format="pdf")
save_plotly(plot, name + count, format="pdf")

with col2:
save_plotly(plot, format="svg")
save_plotly(plot, name + count, format="svg")

with col3:
download_preprocessing_info(plot, count)

download_preprocessing_info(plot, name, count)

else:
st.info("No analysis performed yet.")

0 comments on commit 9e0556a

Please sign in to comment.