How to limit url parameters?


I’ve been playing a bit with url parameterization that syncs with a few widgets.
However, what you put in the url is not limited to what you could select through the widgets.

Using the following example widget, I’m limited to a few options.

window = pn.widgets.RadioButtonGroup(name = "Window", options = ["1D", "1W", "1M", "6M", "1Y", "3Y"], value="1W")

However, if I parameterize the url with:

pn.state.location.sync(window, {'value': 'window'})

I could enter window=None (or any other invalid value) in the url, and would end up with errors down the line.

So, how would I best deal with invalid url parameters?

You could sync to some Parameterized Validation class. When the query args are synced you can react, clean, validate and if valid assign to the widgets.

Maybe the sync function should expose a validation function argument that could make the above easier?

1 Like

Can you be more specific? Does the current implementation not respect the allowed options, and go ahead and set window.value to an invalid setting? I would have thought that window.value would be a Selector parameter that would reject such values already. If it’s not, presumably that should be what happens?