Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS callback in button.js_on_click is runned twice when using custom templates #1700

Closed
rafgonsi opened this issue Oct 27, 2020 · 0 comments · Fixed by #1703
Closed

JS callback in button.js_on_click is runned twice when using custom templates #1700

rafgonsi opened this issue Oct 27, 2020 · 0 comments · Fixed by #1703
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@rafgonsi
Copy link

ALL software version info

panel 0.10.0, bokeh 2.2.2, Python 3.7
OS: Manjaro 20.1.2
Browsers: Firefox 82.0-0.1, Google chrome 86.0.4240.111-1 (issue observed on both)

Description of expected behavior and the observed behavior

The problem appears only when using custom templates. When clicking the button with defined js-callback, the callback is executed twice. In this example I try to open a new tab. When it happens for the first time, browser opens new tab and asks me for permission to display pop-ups. If I agree, then in the future clicking the button will open two tabs. See gif below.

When specifying no template, everything works as expected.

Complete, minimal, self-contained example code that reproduces the issue

import panel as pn

button = pn.widgets.Button(name="Button")
button.js_on_click(code='window.open("https://www.google.com/")')
tmpl = pn.Template("{% extends base %}")
tmpl.add_panel("some_name", button)
tmpl.servable()  # This opens new tab twice

button.servable()  # This works fine

Above code is run with

panel serve bug_example.py

Screenshots or screencasts of the bug in action

bug_panel

Workaround

One can use bokeh buttons to avoid this issue:

from bokeh.models import Button, CustomJS
from bokeh import events

bokeh_button = Button()
callback = CustomJS(code='window.open("https://www.google.com/")')
bokeh_button.js_on_event(events.ButtonClick, callback)
tmpl_bokeh = pn.Template("{% extends base %}")
tmpl_bokeh.add_panel("some_name", bokeh_button)
tmpl_bokeh.servable()
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Oct 27, 2020
@philippjfr philippjfr added this to the v0.10.x milestone Oct 27, 2020
@philippjfr philippjfr modified the milestones: v0.10.x, 0.10.1 Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants