This question is similar to dynamically update objectselector. I have simplified the code for this post.
I have an ObjectSelector param that should modify the path in a FileSelector.
My main question is this: when I modify the ObjectSelector value, e.g., from ‘Original’ to ‘Checked’, the path in the FileSelector changes ( I can print out the path from another cell and it shows the new value), but the FileSelector dropdown contents is not updated accordingly.
import param import panel as pn pn.extension() ORIGINAL_FILES = 'AppTests/*/*/*/Original/*PRE.csv' CHECKED_FILES = 'AppTests/*/*/*/Checked/*PRE.csv' DirList = ['Original', 'Checked'] def update_location(location): if location == 'Original': ps = ORIGINAL_FILES elif location == 'Checked': ps = CHECKED_FILES return ps class Example(param.Parameterized): trigger = param.Integer(default=1) strigger = param.String(default='1') location0 = param.ObjectSelector(default='Original', objects=DirList) file0 = param.FileSelector(path=update_location('Original'), precedence=0.5) @pn.depends(Example.param.location0, watch=True) def update_location0(location): print('ul0 :', location) Example.param.file0.path = update_location(location) Example.trigger += 1 Example.strigger = str(Example.trigger) def update_graph(single_file): if single_file is not None: return pn.pane.Str(single_file) @pn.depends(Example.param.file0, Example.param.strigger, watch=True) def update_graphs(single_file0, trigger): print(Example.location0, ':', single_file0) return update_graph(single_file0) row0 = pn.Row(Example.param.location0) row1 = pn.Row(Example.param.file0) pn.panel(pn.Column( '# Data visualiser', row0, row1, update_graphs) ).servable()
In addition, I have these 2 other questions:
a. when I put the functions inside the class (with param.depends), the update_location function is never called. How can I make sure it is?
b. I have added trigger based on what I saw in other code, but it won’t trigger on an integer, so I added the string strigger. Ugly. This is not an issue when I amke all the functions paret of the class.
I have spent about 2 days trying all possible variations on this but have not been able to make it work. Any help would be much appreciated.