Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 39 ยท Collaboration and Deployment

Voila, Dashboards and Notebook Apps

Serve a notebook as a standalone web app with Voila: hide code, add ipywidgets controls, deploy to a server, and compare it with Streamlit, Panel and Dash.

A notebook is written for people who read code. Many of the people who need your results do not. Voila turns a notebook into a web page that shows only the outputs and the widgets, runs the code on the server, and gives each visitor a private kernel. The result feels like a small application, and you built it without writing HTML or JavaScript.

Voila is not available on this site. This lesson describes the real commands and shows runnable stand-ins for the logic: a widget-driven calculation written as plain functions, and a model of how Voila handles each visitor.

How Voila works

When someone opens a Voila URL, the server starts a kernel, executes the notebook from the top, and sends the rendered result. Code cells are hidden by default. Widgets in the output stay live: when the visitor moves a slider, the callback runs in that visitor's kernel, and the page updates.

flowchart LR
  V["Visitor opens /voila/render/app.ipynb"] --> S["Voila server"]
  S --> K["New kernel for this visitor"]
  K --> N["Run notebook top to bottom"]
  N --> R["Rendered page: outputs and widgets only"]
  R --> V

Each visitor gets an isolated kernel, which is why state does not leak between users and also why costs grow with traffic.

Run it

Terminal
pip install voila ipywidgets
voila app.ipynb                     # serves one notebook at http://localhost:8866
voila notebooks/                    # serves a directory with a gallery page
voila app.ipynb --port=8080 --Voila.ip=0.0.0.0
voila app.ipynb --strip_sources=False    # show code too
voila app.ipynb --template=gridstack     # grid layout (needs voila-gridstack)

JupyterLab also has a Voila preview button in the notebook toolbar (with the voila extension), which shows the app view next to the notebook while you build it.

A widget-driven app

The usual building block is ipywidgets: sliders, dropdowns, buttons and output areas. Here is a small loan calculator as it would appear in app.ipynb:

Python
import ipywidgets as widgets
from IPython.display import display

amount = widgets.IntSlider(value=10000, min=1000, max=50000, step=500, description="Amount")
rate = widgets.FloatSlider(value=5.0, min=0.5, max=15.0, step=0.1, description="Rate %")
years = widgets.IntSlider(value=5, min=1, max=30, description="Years")
out = widgets.Output()

def update(change=None):
    with out:
        out.clear_output()
        print(f"Monthly payment: {monthly_payment(amount.value, rate.value, years.value):.2f}")

for w in (amount, rate, years):
    w.observe(update, names="value")

display(widgets.VBox([amount, rate, years, out]))
update()

On the Voila page the visitor sees three sliders and the result line; the code is hidden. The key idea: keep the calculation in a plain function (monthly_payment), and keep the widget wiring thin. The function is testable and reusable (see moving code into modules). The next cell is the function itself, plus a check, which you can run here.

Python The calculation behind the widgets

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first line prints 188.71, the standard payment for a 5-year loan of 10,000 at 5 percent. The zero-rate special case avoids division by zero.

Simulate the observe pattern

Widgets use the observer pattern: a value changes, registered callbacks run. This model has no Jupyter dependency, so it runs here, and it shows what observe does.

Python Observer pattern (what widget.observe does)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In the real library the front end moves the slider and sends the new value to the kernel; the callback then runs there.

Hide what visitors should not see

  • Code is hidden by default. Output of print statements and error tracebacks still appear, so avoid noisy debug prints.
  • Do not read secrets in a notebook that Voila serves. The server renders the output of every cell, and an accidental print(os.environ) would reach visitors. See notebook security.
  • Voila executes only the notebook; it does not let visitors edit code. Treat it as safe in that sense, but keep inputs validated, because widget values are still user input.

Deployment

Voila is a normal Python web server (Tornado). To publish it you need a host that runs it: a virtual machine, a container, or a platform such as Heroku or Render. A common Dockerfile installs your requirements, copies the notebook, and runs voila --port=$PORT --no-browser app.ipynb. Put it behind a reverse proxy with HTTPS and an authentication layer if the content is private.

Plan for scale: every open page holds a kernel and its memory. Set --VoilaExecutor.timeout, limit concurrent users with your platform's limits, and preload shared data to a file or database instead of loading a large CSV in every kernel. Voila also supports preheated kernels (--preheat_kernel=True) to cut startup time for each visit.

Voila versus other options

Tool Style Good for
Voila existing notebook becomes the app fast sharing of a notebook, widget demos
Streamlit a Python script with st. calls richer data apps, simple deployment
Panel libraries around HoloViz, runs in notebooks and servers linked plots, big data dashboards
Dash Plotly components and callbacks production-style dashboards with a web team

Voila wins when the notebook already exists and you want to show it quickly. When the app grows (many pages, authentication, caching), a dedicated framework is usually a better home, and the calculation functions you kept separate can move with you.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Voila show by default?

    Voila renders the notebook as an app: results and widgets, not source code.
  2. 2. How does Voila isolate visitors?

    A separate kernel per visitor prevents shared state but uses memory per open page.
  3. 3. Why keep calculations in plain functions instead of inside widget callbacks?

    Thin widget code around pure functions is easier to test and to reuse in another framework.
  4. 4. Which is a risk of serving a notebook with Voila?

    Everything a cell prints is rendered, so never output secrets or debug details.

Summary

  • Voila serves a notebook as a read-only app: code hidden, widgets live, one kernel per visitor.
  • Build interactive parts with ipywidgets and keep logic in plain functions.
  • Deploy it as a normal web server behind HTTPS, with limits on kernels and timeouts.
  • For larger apps consider Streamlit, Panel or Dash.

Next: Structuring a Notebook