Url parameter sync issue

Hi,

I am trying with sync feature of panel.But I am not able to clear URL parameter when visiting other page.


Here is the code I’ve written

import panel as pn
import param

class Example(param.Parameterized):
    selected_name = param.String(default='')

class Example2(param.Parameterized):
    selected_city = param.String(default='')

def show_data(page):
    if page=='First Page':
        ex_obj = Example()
        gspec = pn.GridSpec()
        pn.state.location.sync(ex_obj, {'selected_name': 'selected_name'})
        gspec[0, 0] = pn.widgets.TextInput.from_param(ex_obj.param.selected_name)

    elif page=='Second Page':
        ex2_obj = Example2()
        gspec = pn.GridSpec()
        pn.state.location.sync(ex2_obj, {'selected_city': 'selected_city'})
        gspec[0, 0] = pn.widgets.TextInput.from_param(ex2_obj.param.selected_city)

    tabs = pn.Tabs(('Analytics', gspec))
    return tabs

def show(page):
    tabs = show_data(page)
    return tabs

page = pn.widgets.RadioButtonGroup(
    value='First Page',
    options=['First Page', 'Second Page'],
    name="Page",
    button_type="success",
    orientation="vertical")

ishow = pn.bind(show, page=page)

pn.template.FastListTemplate(
    title="Data Analytics",
    sidebar=[page],
    main=[ishow]).servable()

As you can see in the attached screenshot, selected_name is getting carry forwarded on the second page which should not happen. I don’t know how can I not let it happen or is there any workaround.

python==3.10.10
panel==1.3.6

1 Like

Hi keyur_ds

If instead a single file with two pages app you reorganize into two files with a single page each app then things will get much easier for you. Would that be possible?