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

Changing alert properties after instantiation #1725

Closed
nritsche opened this issue Oct 30, 2020 · 0 comments · Fixed by #1734
Closed

Changing alert properties after instantiation #1725

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

Comments

@nritsche
Copy link
Contributor

After creating an alert with

my_alert = pn.pane.Alert("foo", alert_type="primary")

I want to change it’s properties later. I tried

my_alert.alert_type = "success"
my_alert.object = "foo!"

, which works, but gives me a

  File "/home/rick/bondia/bondia/gui.py", line 209, in _click_opinion
    my_alert.alert_type = "success"
  File "/home/rick/.local/lib/python3.8/site-packages/param/parameterized.py", line 302, in _f
    instance_param.__set__(obj, val)
  File "/home/rick/.local/lib/python3.8/site-packages/param/parameterized.py", line 304, in _f
    return f(self, obj, val)
  File "/home/rick/.local/lib/python3.8/site-packages/param/parameterized.py", line 915, in __set__
    obj.param._call_watcher(watcher, event)
  File "/home/rick/.local/lib/python3.8/site-packages/param/parameterized.py", line 1554, in _call_watcher
    watcher.fn(event)
  File "/home/rick/.local/lib/python3.8/site-packages/panel/reactive.py", line 175, in _param_change
    self._update_model(events, msg, root, model, doc, comm)
  File "/home/rick/.local/lib/python3.8/site-packages/panel/reactive.py", line 132, in _update_model
    self._changing[root.ref['id']] = [
  File "/home/rick/.local/lib/python3.8/site-packages/panel/reactive.py", line 134, in <listcomp>
    if not model.lookup(attr).property.matches(getattr(model, attr), value)
  File "/home/rick/.local/lib/python3.8/site-packages/bokeh/core/has_props.py", line 417, in lookup
    return getattr(cls, name)
AttributeError: type object 'HTML' has no attribute 'alert_type'

As suggested by @MarcSkovMadsen, adding this before instantiation of the alert solves the issue (see https://discourse.holoviz.org/t/how-to-change-alert-properties-after-creation/1369/2):

Alert._rename = {**Markdown._rename, "alert_type": None} 

It should probably also be possible to change the alert text with my_alert.text = "bar", but one has to do my_alert.object = "bar" to archieve this.

software version info

Ubuntu 20.04.1 LTS
Python 3.8.5
panel 0.10.1

@philippjfr philippjfr added this to the v0.10.2 milestone Nov 1, 2020
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Nov 1, 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