jonescompneurolab / hnn-core

Simulation and optimization of neural circuits for MEG/EEG source estimates
https://jonescompneurolab.github.io/hnn-core/
BSD 3-Clause "New" or "Revised" License
51 stars 50 forks source link

GUI exporting simulations to csv #718

Closed gtdang closed 2 months ago

gtdang commented 5 months ago

Add a button to export simulations to a csv file

Related to #709

kmilo9999 commented 2 months ago

@ntolley I wonder if you have pictured how this looks from the GUI side. ipywidgets (that a I know) doesn't have a folder selector widget. I've been looking on creating a custom widget but it looks a bit more complicated that I initially thought.

ntolley commented 2 months ago

Honestly I assumed there would be one already built in. This project seems to achieve what we want, but it's not great to add a uncommonly used/supported dependency for just one function.

ntolley commented 2 months ago

Alternatively could the FileUpload class source code by recycled for folder selection? I'll admit reading this it's a bit unclear if this is actually possible...

jasmainak commented 2 months ago

Why do you need a folder selector widget? To export multiple trials?

jasmainak commented 2 months ago

Try this:

from ipywidgets import HTML
from IPython.display import display

import base64

res = 'computed results'

#FILE
filename = 'res.txt'
b64 = base64.b64encode(res.encode())
payload = b64.decode()

#BUTTONS
html_buttons = '''<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<a download="{filename}" href="data:text/csv;base64,{payload}" download>
<button class="p-Widget jupyter-widgets jupyter-button widget-button mod-warning">Download File</button>
</a>
</body>
</html>
'''

html_button = html_buttons.format(payload=payload,filename=filename)
display(HTML(html_button))

probably what you're looking for

kmilo9999 commented 2 months ago

@jasmainak Awesome! Thanks, you saved me a lot of time!