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

Does voila support display widgets in callback func or how? #499

Closed
xdyuchen opened this issue Dec 13, 2019 · 1 comment
Closed

Does voila support display widgets in callback func or how? #499

xdyuchen opened this issue Dec 13, 2019 · 1 comment

Comments

@xdyuchen
Copy link

xdyuchen commented Dec 13, 2019

Hello!
I want to show some widget in a callback event, code is run ok in notebook but not show on voila.

support? or how to show widgets in callback func?

import ipywidgets as widgets

slider = widgets.FloatSlider(description="$x$", value=4)
text = widgets.FloatText(disabled=True, description="$x^2$")


def compute(*ignore):
    text.value = str(slider.value ** 2)


slider.observe(compute, "value")


def check_support(*ignore):
    test_text = widgets.Text()
    #     not showing
    display(test_text)
    text.value = 0.1


check_btn = widgets.Button(description="check_support")
display(check_btn)

check_btn.on_click(check_support)

widgets.VBox([slider, text])
@jtpio
Copy link
Member

jtpio commented Dec 27, 2019

@xdyuchen and using the Output widget?

So the code above becomes:

import ipywidgets as widgets

slider = widgets.FloatSlider(description="$x$", value=4)
text = widgets.FloatText(disabled=True, description="$x^2$")
out = widgets.Output()


def compute(*ignore):
    text.value = str(slider.value ** 2)


slider.observe(compute, "value")

@out.capture()
def check_support(*ignore):
    test_text = widgets.Text()
    #     not showing
    display(test_text)
    text.value = "0.1"


check_btn = widgets.Button(description="check_support")
display(check_btn)

check_btn.on_click(check_support)

display(widgets.VBox([slider, text]))
out

@xdyuchen xdyuchen closed this as completed Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants