-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from MannLabs/simplify_analysis-III
simplify_analysis-III
- Loading branch information
Showing
5 changed files
with
132 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,32 @@ | ||
import io | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
|
||
from alphastats.gui.utils.analysis_helper import display_plot | ||
from alphastats.gui.utils.ui_helper import ( | ||
StateKeys, | ||
convert_df, | ||
init_session_state, | ||
sidebar_info, | ||
) | ||
|
||
|
||
def display_plotly_figure(plot): | ||
st.plotly_chart(plot) | ||
|
||
|
||
def save_plotly(plot, name, format): | ||
# Create an in-memory buffer | ||
buffer = io.BytesIO() | ||
# Save the figure as a pdf to the buffer | ||
plot.write_image(file=buffer, format=format) | ||
st.download_button( | ||
label="Download as " + format, data=buffer, file_name=name + "." + format | ||
) | ||
|
||
|
||
def download_preprocessing_info(plot, name, count): | ||
preprocesing_dict = plot.preprocessing | ||
df = pd.DataFrame(preprocesing_dict.items()) | ||
filename = "plot" + name + "preprocessing_info.csv" | ||
csv = convert_df(df) | ||
print("preprocessing" + count) | ||
st.download_button( | ||
"Download DataSet Info as .csv", | ||
csv, | ||
filename, | ||
"text/csv", | ||
key="preprocessing" + count, | ||
) | ||
|
||
|
||
init_session_state() | ||
sidebar_info() | ||
|
||
st.markdown("### Results") | ||
|
||
if not st.session_state[StateKeys.PLOT_LIST]: | ||
st.info("No analysis saved yet.") | ||
st.stop() | ||
|
||
if StateKeys.PLOT_LIST in st.session_state: | ||
for count, plot in enumerate(st.session_state[StateKeys.PLOT_LIST]): | ||
print("plot", type(plot), count) | ||
count = str(count) | ||
|
||
st.markdown("\n\n") | ||
name = plot[0] | ||
plot = plot[1] | ||
if name == "ttest": | ||
plot = plot.plot | ||
st.write(name) | ||
|
||
display_plotly_figure(plot) | ||
for count, saved_item in enumerate(st.session_state[StateKeys.PLOT_LIST]): | ||
print("plot", type(saved_item), count) | ||
|
||
col1, col2, col3 = st.columns([1, 1, 1]) | ||
method = saved_item[0] | ||
plot = saved_item[1] | ||
|
||
with col1: | ||
save_plotly(plot, name + count, format="pdf") | ||
st.markdown("\n\n\n") | ||
st.markdown(f"#### {method}") | ||
|
||
with col2: | ||
save_plotly(plot, name + count, format="svg") | ||
if st.button("x remove analysis", key="remove" + method + str(count)): | ||
st.session_state[StateKeys.PLOT_LIST].remove(saved_item) | ||
st.rerun() | ||
|
||
with col3: | ||
download_preprocessing_info(plot, name, count) | ||
else: | ||
st.info("No analysis performed yet.") | ||
display_plot(method + str(count), plot, show_save_button=False) |
Oops, something went wrong.