Skip to content

Commit

Permalink
fixing download button
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPdeS committed Dec 15, 2024
1 parent 8b1b958 commit 0e2da10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions PyMieSim/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_plot(self, measure: str, xaxis: str):
buf.close()
return f"data:image/png;base64,{encoded_image}"

def save_func(self, filename: str, measure: str, xaxis: str):
def save_func(self, filename: str, measure: str):
"""
Save the simulation data to a CSV file.
Expand All @@ -79,16 +79,14 @@ def save_func(self, filename: str, measure: str, xaxis: str):
xaxis : str
The parameter to include on the x-axis in the saved data.
"""
dataframe = interface(
return interface(
source_kwargs=self.source_section.data,
scatterer_kwargs=self.scatterer_section.data,
detector_kwargs=self.detector_section.data,
measure=measure,
add_units=False
)

dataframe.to_csv(filename, sep=',')

def setup_layout(self):
"""
Define the layout of the Dash app.
Expand Down
7 changes: 3 additions & 4 deletions PyMieSim/gui_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,9 @@ def update_plot_button_style(xaxis_value: str) -> tuple:
Input(self.save_button_id, "n_clicks"),
State(self.plot_ready_store_id, "data"),
State(self.filename_input_id, "value"),
State(self.dropdown_id, "value"),
State(self.xaxis_input_id, "value")
State(self.dropdown_id, "value")
)
def save_data(n_clicks: int, plot_ready: bool, filename: str, measure: str, xaxis: str) -> dict:
def save_data(n_clicks: int, plot_ready: bool, filename: str, measure: str) -> dict:
"""
Trigger file download when the save button is clicked.
Expand All @@ -552,7 +551,7 @@ def save_data(n_clicks: int, plot_ready: bool, filename: str, measure: str, xaxi
File content and metadata for download, or None if conditions are not met.
"""
if n_clicks > 0 and plot_ready:
dataframe = save_func(measure, xaxis)
dataframe = save_func(filename=filename, measure=measure)
content = dataframe.to_csv(index=False)
return {"content": content, "filename": filename, "type": "text/csv"}
return None
Expand Down

0 comments on commit 0e2da10

Please sign in to comment.