Skip to content

Outside JupyterLab

The Metanno tab is convenient while you prepare a project, but annotators do not always use JupyterLab, and a view sometimes belongs in a notebook next to an analysis. In this tutorial, you show the view of Review entities below a notebook cell, then serve it as a web app.

Before you start

Follow Review entities first: this tutorial reuses its oncology.pret file and its review_entities view.

In a notebook output

A view is a function returning a Pret component, so calling it at the end of a cell shows the view below the cell:

import sys
from pathlib import Path

from pret import load_store

sys.path.insert(0, str(Path("~/metanno-home/recipes").expanduser()))
from review_entities import main

store = load_store("~/metanno-home/annotations/oncology.pret")
main(store)

The output is the same interface as the tab, editing the same file, so an edit made here also shows in the Metanno tab.

From an output to a tab

Right-click a Pret output to open it in a new browser tab, or to detach it into its own JupyterLab panel, see From notebook to app.

As a web app

To give annotators a link instead of a notebook, serve the view with Pret. Save this script as app.py:

import sys
from pathlib import Path

from pret import load_store, run

sys.path.insert(0, str(Path("~/metanno-home/recipes").expanduser()))
from review_entities import main

if __name__ == "__main__":
    store = load_store("~/metanno-home/annotations/oncology.pret")
    run(main(store), port=5000)

then start it from a terminal, in its folder:

python app.py

and open http://localhost:5000. Edits are saved to oncology.pret, like in the tab, and the notebook, the tab and the app show each other's edits since they all use the same file.

Who can reach the app

run only listens to your own machine by default. run(..., host="0.0.0.0") makes the app reachable from other machines, without any login: anyone who can reach the port can read and edit the annotations. Only do it on a network you trust, or behind the access control of your institution.

Next

You have gone through the whole path, from a pandas table to your own annotation app. The components pages describe each widget in detail, and the Pret tutorials explain the framework under Metanno.