Skip to content

Commit

Permalink
added download html button
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Nov 29, 2022
1 parent bb52baf commit 93e465d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/openmc_plot/geometry_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

6 changes: 3 additions & 3 deletions src/openmc_plot/regularmesh_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
10 changes: 10 additions & 0 deletions src/openmc_plot/source_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 3 additions & 3 deletions src/openmc_plot/weightwindows_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 93e465d

Please sign in to comment.