SimonBiggs / scriptedforms

Quickly create live-update GUIs for Python packages using Markdown and simple HTML elements.
Apache License 2.0
508 stars 34 forks source link

Watchdog file list in a table #182

Closed robmarkcole closed 6 years ago

robmarkcole commented 6 years ago

I have a use case which may require functionaltiy added. I want to use scriptedforms to capture a list of images saved during an experiment run. I will use a form to enter the experiment parameters (in my case camera exposure time etc) and I want the form to display a list of all the .jpg images saved in a folder. At the and of the experiment run I will post the paths of all saved .jpg to an external database. Thereore my request is: live updating table of all .jpg files in a folder. Is this possible?

SimonBiggs commented 6 years ago

Yup. Can definitely be done with the current set up.

Something like the following should work. I haven't tested it, just wrote it in here. But it should be close.


<section-start>

```python
import os
from glob import glob
from IPython.display import display, Markdown

path_to_watch = '/a/path/here'
glob_string = os.path.join(path_to_watch, '*.jpg')
```

</section-start>

<section-filechange paths="[path_to_watch]">

```python
filepath_list = glob(glob_string)
markdown_string = '\n'.join([
    "* {}".format(filepath)
    for filepath in filepath_list
])
display(Markdown(markdown_string))
```

</section-filechange>
robmarkcole commented 6 years ago

With the same application in mind, is it possible to programatically display input text fields, in this case using the column headers from a database?

SimonBiggs commented 6 years ago

Yup, programmatically create a pandas dataframe and use the table variable. Would that work?

robmarkcole commented 6 years ago

Your example works nicely

image

SimonBiggs commented 6 years ago

Good to hear :)