From 93e465dfdb056fd54ef85b2aa107b9a3851bafc0 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 29 Nov 2022 16:18:53 +0000 Subject: [PATCH] added download html button --- src/openmc_plot/geometry_tab.py | 8 ++++---- src/openmc_plot/regularmesh_tab.py | 6 +++--- src/openmc_plot/source_tab.py | 10 ++++++++++ src/openmc_plot/weightwindows_tab.py | 6 +++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/openmc_plot/geometry_tab.py b/src/openmc_plot/geometry_tab.py index 4f3f87a..5ebabb0 100644 --- a/src/openmc_plot/geometry_tab.py +++ b/src/openmc_plot/geometry_tab.py @@ -205,15 +205,15 @@ def create_geometry_tab(): colors=my_colors, color_by=color_by, ) - geom_plt.figure.savefig("geometry_image.png") + geom_plt.figure.savefig("openmc_plot_geometry_image.png") - col2.image("geometry_image.png", use_column_width="always") + col2.image("openmc_plot_geometry_image.png", use_column_width="always") - with open("geometry_image.png", "rb") as file: + with open("openmc_plot_geometry_image.png", "rb") as file: col1.download_button( label="Download image", data=file, - file_name="geometry_image.png", + file_name="openmc_plot_geometry_image.png", mime="image/png" ) diff --git a/src/openmc_plot/regularmesh_tab.py b/src/openmc_plot/regularmesh_tab.py index 9af7d25..df0a324 100644 --- a/src/openmc_plot/regularmesh_tab.py +++ b/src/openmc_plot/regularmesh_tab.py @@ -132,11 +132,11 @@ def create_regularmesh_tab(): plt.colorbar(label=cbar_label) col2.pyplot(plt) - plt.savefig('regularmesh_image.png') - with open("regularmesh_image.png", "rb") as file: + plt.savefig('openmc_plot_regularmesh_image.png') + with open("openmc_plot_regularmesh_image.png", "rb") as file: col1.download_button( label="Download image", data=file, - file_name="regularmesh_image.png", + file_name="openmc_plot_regularmesh_image.png", mime="image/png" ) diff --git a/src/openmc_plot/source_tab.py b/src/openmc_plot/source_tab.py index 1075616..aca3de4 100644 --- a/src/openmc_plot/source_tab.py +++ b/src/openmc_plot/source_tab.py @@ -61,3 +61,13 @@ def create_source_tab(): fig = new_source.plot_source_position(figure=fig, n_samples=n_samples) col2.plotly_chart(fig) + + fig.write_html('openmc_plot_source_image.html') + + with open("openmc_plot_source_image.html", "rb") as file: + col1.download_button( + label="Download image", + data=file, + file_name="openmc_plot_source_image.html", + mime=None + ) diff --git a/src/openmc_plot/weightwindows_tab.py b/src/openmc_plot/weightwindows_tab.py index d04422d..adeaec5 100644 --- a/src/openmc_plot/weightwindows_tab.py +++ b/src/openmc_plot/weightwindows_tab.py @@ -126,12 +126,12 @@ def create_weightwindow_tab(): ) plt.colorbar(label=upper_or_lower) col2.pyplot(plt) - plt.savefig("weightwindow_image.png") + plt.savefig("openmc_plot_weightwindow_image.png") - with open("weightwindow_image.png", "rb") as file: + with open("openmc_plot_weightwindow_image.png", "rb") as file: col1.download_button( label="Download image", data=file, - file_name="weightwindow_image.png", + file_name="openmc_plot_weightwindow_image.png", mime="image/png" )