FileSelector modify path via ObjectSelector - dropdown list does not change

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.

The problem is that at least currently changing the path on the parameter does not automatically trigger an update/refresh in the selectable objects, by calling the update method yourself you can trigger this update:

@pn.depends(Example.param.location0, watch=True)
def update_location0(location):
    print('ul0 :', location)
    Example.param.file0.path = update_location(location)
    Example.param.file0.update() # Add this

Could you file an issue about this with Panel?

Thank you very much. That worked. I have submitted an issue about this with Panel on github (https://github.com/holoviz/panel/issues/1345).
Your help is much appreciated. Also, I am really favorably impressed with Panel and HoloViews.

How about the other 2 quesitons?

You should reference the parameter as a string and then you probably want to make an instance, e.g.:

    @pn.depends('location0', watch=True)
    def update_location0(self):
        self.param.file0.path = update_location(self.location0)
        self.param.file0.update()

...
example = Example()

pn.panel(pn.Column(
    '# Data visualiser',
    example.param.location0,
    example.param.file0,
    update_graphs)
).servable()

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.

This is a bug because .trigger is a method on the keyword, an issue on param to address this would be appreciated. For now you can get around it by calling your parameter something other than trigger.