-
Notifications
You must be signed in to change notification settings - Fork 39
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
display
shows nothing while directly outputing the widget is OK
#762
Comments
Hi there, I am able to reproduce. I'm not sure this is something we can resolve in the experimental API. I'm not sure why, but it seems like the global I was able to get this to work by importing from ++ from IPython.display import display
from pydantic import BaseModel
import anywidget.experimental
import psygnal
@anywidget.experimental.widget(esm="""
function render({ model, el }) {
let button = document.createElement("button");
button.innerHTML = `count is ${model.get("value")}`;
button.addEventListener("click", () => {
model.set("value", model.get("value") + 1);
model.save_changes();
});
model.on("change:value", () => {
button.innerHTML = `count is ${model.get("value")}`;
});
el.classList.add("counter-widget");
el.appendChild(button);
}
export default { render };
""")
@psygnal.evented
class HelloWidget(BaseModel):
value: int = 0
display(HelloWidget(value=42)) For context, the |
For anyone else reading this, import anywidget
import traitlets
class CounterWidget(anywidget.AnyWidget):
_esm = """
function render({ model, el }) {
let count = () => model.get("value");
let btn = document.createElement("button");
btn.innerHTML = `count is ${count()}`;
btn.addEventListener("click", () => {
model.set("value", count() + 1);
model.save_changes();
});
model.on("change:value", () => {
btn.innerHTML = `count is ${count()}`;
});
el.appendChild(btn);
}
export default { render };
"""
value = traitlets.Int(0).tag(sync=True)
display(CounterWidget()) |
Ah you know what, I think I figured something out. I don't think it is related to the display(HelloWidget(value=42)) Does not show anything for me. But assigning the widget to variable first: w = HelloWidget(value=42)
display(w) does work for me. Would you be able to try both and confirm? I can have a look to understand the underlying behavior later if this is the root of the issue. |
Thanks for the exploration! ok, now i’m realizing that this is due to fact we make widgets with our Descriptor weakrefable. The comms are getting cleaned up. cc: @tlambert03 |
Thanks, then look like this can be fixed and looking forward to the future release! |
Describe the bug
Hi thanks for the lib! However, it seems
display
shows nothing.This is OK:
But this shows nothing:
With logs being normal (no errors)
Reproduction
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: