Voila in the long run is going to be worth the investment in time to learn. (And that was a good suggestion from your other post.) However, there is also Appmode that makes things a little simpler than Voila because the output is what you see but not the code. With Voila you have to make sure you are generating output in ipywidgets. You may get farther faster with Appmode for now. Perhaps? Or it might come in handy to know about Appmode later.
I believe the specific issue with your demo code is that you need to specify a place for the output from the function to display in that will be updated after the button is pressed, that will be in widgets.Output()
. Try this:
# sort of based on https://github.com/voila-dashboards/voila-material/issues/18
import ipywidgets as widgets
from IPython.display import display
output = widgets.Output()
@output.capture(clear_output=False,wait=True) # based on https://github.com/jupyter-widgets/ipywidgets/issues/1846 and https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html
def sayHello(b):
print('Hello world!')
run_button = widgets.Button(
description = 'run'
)
run_button.on_click(sayHello)
display(run_button)
output
(You can change the line @output.capture(clear_output=False,wait=True)
to @output.capture(clear_output=True,wait=True)
if you want it to not to keep adding more printed copies of the text below each time and instead just write over what was there. The latter is probably what you want in most real cases as you’d probably be updating the text there by overwriting it and not adding a longer list of output text. )
I have done static and interactive plots in Voila. Go to here. If you go to https://github.com/fomightez/3Dscatter_plot-binder and launch Binder and then choose the notebook listed as ‘3D scatter plot using data in a file and Voila interface’. That is a pretty advanced interface as you’ll see. I have some more basic interfaces working at https://github.com/fomightez/communication_voila , and something among them might be more helpful for you understanding displaying basic plots than the advanced examples in the Voila Gallery. Animations or interactive plots are you trying to do? I have yet to do animations in Voila, but animations in general can be tricky given the classic notebook interface and JupyterLab handling them differently, see here.