# Syncing URL Session Arguments from Widget Value

**URL:** <https://discourse.holoviz.org/t/syncing-url-session-arguments-from-widget-value/2926>\
**Category:** Panel\
**Created:** [October 11, 2021, 12:14pm UTC](https://discourse.holoviz.org/t/syncing-url-session-arguments-from-widget-value/2926 "2021-10-11T12:14:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahar540](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sahar540](https://discourse.holoviz.org/u/sahar540)\
**Post date:** [October 11, 2021, 12:14pm UTC](https://discourse.holoviz.org/t/syncing-url-session-arguments-from-widget-value/2926/1 "2021-10-11T12:14:48Z")

</div>

Hey everyone!  
I am building a dashboard, it’s URL looks like this

```auto
http://10.0.1.85:9990/main?from=2021-10-04&to=2021-10-10&field_id=2284811

```

From it, I take the sessions arguments (from, to, field\_id) using

```auto
pn.state.session_args.get('from')[0].decode('UTF-8')

```

And set it as the default value of three widgets using -

```auto
date_from_wig = pn.widgets.DatetimeInput(name='From', value=pd.to_datetime(pn.state.session_args.get('from')[0].decode('UTF-8')))

```

I am trying to update the URL of the session when a widget value changes using -

```auto
if pn.state.location:
    pn.state.location.sync(date_from_wig, {'value': 'from'})

```

Thing is - I want to reformat the widget value, basically doing something like this -

```auto
pn.state.location.sync(date_from_wig, {pd.to_datetime('value').strftime("%Y-%m-%d"): 'from'})

```

Do you have any idea how I can manipulate the value from the widget before syncing it to the session URL?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Hoxbro](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/hoxbro/32/3590_2.png) [@Hoxbro](https://discourse.holoviz.org/u/Hoxbro)\
**Post date:** [October 11, 2021, 6:33pm UTC](https://discourse.holoviz.org/t/syncing-url-session-arguments-from-widget-value/2926/2 "2021-10-11T18:33:54Z")

</div>

I think you are over complicating some part of you code.

If I replace `DatetimeInput` with `DatePicker` something like the following will work:

```python
import panel as pn
import param
from datetime import date
pn.extension()

def main():
    start = pn.widgets.DatePicker(name="Start date", value=date.today())
    end = pn.widgets.DatePicker(name="End date", value=date.today())
    field = pn.widgets.IntInput(name="Field ID", value=1)

    if pn.state.location:
        pn.state.location.sync(start, {"value": "from"})
        pn.state.location.sync(end, {"value": "to"})
        pn.state.location.sync(field, {"value": "field_id"})

    return pn.Column(start, end, field)

pn.panel(main).servable()

```

If you want an Input instead of DatePicker, a small hack is needed to change the `param.Date` to `param.CalendarDate` for the widget like and change the format:

```python
class DateInput(pn.widgets.DatetimeInput):
    format = param.String(default=r'%Y-%m-%d')
    value = param.CalendarDate(default=None)

```

And then replace `pn.widgets.DatePicker` with `DateInput` in the first code block.
