基于python的jupyter notebook是数据科学常用的工具,不过也会有时候需要我们构建一些小工具自用,甚至让别人去使用,那么怎么最快的构建这样的应用,voila就提供了一种这种可能性。
注意voila的拼写,如果写成viola就是另一个包了。
安装voila很简单pip install voila
就可以,使用更简单,只要运行voila jupyter_notebook_name.ipynb
就可以了,其实最重要的是构建notebok应用,这里需要用到ipywidgets(jupyter原名ipython)
第一个例子,a+b=?
import ipywidgets as widgets
两个文本框
input_text = widgets.Text(description='A=')
input_text2 = widgets.Text(description='B=')
一个label作为加号,向右偏移30px,也就是距离左侧30px
plus_text = widgets.Label(value='+', layout=widgets.Layout(left='30px'))
提交按钮