8000 Check if there are any query parameters in `baseurl` and adds it to `location.search` if possible by hoxbro · Pull Request #3214 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@hoxbro
Copy link
Member
@hoxbro hoxbro commented Feb 26, 2022

I don't think this fixes any issues. Though, it fixes an annoyance I have had for some time...

This PR check for any query parameters in baseurl and adds it to location.search if possible. This means that the query parameter will load the first time and not have to load twice. This can be seen in the following examples where the before examples first shows 0 and then the query value, where the after examples shows the query value instantly.

Single

before.mp4
after.mp4
Code
import time

import panel as pn
import param


class ButtonClick(pn.viewable.Viewer):
    def __init__(self, **params):
        self.button = pn.widgets.Button(name="Click")
        super().__init__(**params)
        if pn.state.location:
            pn.state.location.sync(self.button, {"clicks": "clicks"})

    @param.depends("button.clicks")
    def _update_button_click(self):

        time.sleep(0.3)  # Just to give time to show it

        return pn.pane.Markdown(f"# {self.button.clicks}")

    def __panel__(self):
        return pn.Column(self.button, self._update_button_click)


if __name__ == "__main__":
    app = ButtonClick()
    app.show(port=5007)
elif __name__.startswith("bokeh"):
    app = ButtonClick()
    app.servable()

Multi

before_multi.mp4
after_multi.mp4
Code
import time

import panel as pn
import param


class ButtonClick(pn.viewable.Viewer):
    def __init__(self, **params):
        self.button1 = pn.widgets.Button(name="Click")
        self.button2 = pn.widgets.Button(name="Click")
        self.button3 = pn.widgets.Button(name="Click")
        super().__init__(**params)
        if pn.state.location:
            pn.state.location.sync(self.button1, {"clicks": "button1"})
            pn.state.location.sync(self.button2, {"clicks": "button2"})
            pn.state.location.sync(self.button3, {"clicks": "button3"})

    @param.depends("button1.clicks", "button2.clicks","button3.clicks")
    def _update_button_click(self):

        time.sleep(0.3)  # Just to give time to show it
        return pn.Column(
            pn.pane.Markdown(f"# {self.button1.clicks}"),
            pn.pane.Markdown(f"# {self.button2.clicks}"),
            pn.pane.Markdown(f"# {self.button3.clicks}"),
        )

    def __panel__(self):
        return pn.Column(self.button1, self.button2, self.button3, self._update_button_click)


if __name__ == "__main__":
    app = ButtonClick()
    app.show(port=5007)
elif __name__.startswith("bokeh"):
    app = ButtonClick()
    app.servable()

@codecov
Copy link
codecov bot commented Feb 26, 2022

Codecov Report

Merging #3214 (6a99676) into master (bc71dc7) will decrease coverage by 0.02%.
The diff coverage is 28.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3214      +/-   ##
==========================================
- Coverage   83.15%   83.12%   -0.03%     
==========================================
  Files         193      193              
  Lines       25716    25726      +10     
==========================================
+ Hits        21384    21385       +1     
- Misses       4332     4341       +9     
Impacted Files Coverage Δ
panel/io/state.py 68.97% <28.57%> (-1.22%) ⬇️
panel/io/reload.py 69.23% <0.00%> (-2.20%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc71dc7...6a99676. Read the comment docs.

@hoxbro hoxbro changed the title Check if base url have any search parameters for pn.state.location Check if there are any query parameters in baseurl and adds it to location.search if possible Feb 28, 2022
@philippjfr
Copy link
Member

Thanks @hoxbro! This has annoyed me too but not enough to actually investigate yet.

@philippjfr philippjfr merged commit e1d76f4 into holoviz:master Mar 1, 2022
@hoxbro hoxbro deleted the instant_sync branch March 2, 2022 05:40
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0