I am using Spacy to visualize NERs in a notebook as follows:
import spacy
from spacy import displacy
text = "When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously."
nlp = spacy.load("en_core_web_sm")
doc = nlp(text)
displacy.render(doc, style="ent")
(This is the example in the spacy documentation)
So far so good.
The question is if it is possible to access the HTML object itself, not just rendering it, in order to add functionality via HTML to it. More precisely what I am looking for is a way to fire a function when clicking everyone of those "buttons". this work around I am looking for is meant to work in a jupyter hub, i.e. Jupyter lab, so solutions using any webframe like streamlit or flask or whatever that can be run in a local server are out of scope.
thanks.
EDIT 1: If you use the following code in a Jupyter lab you can get the plain HTML:
displacy.render(doc, style="ent", jupyter'False'))
you would get:
'<div class="entities" style="line-height: 2.5; direction: ltr">When \n<mark class="entity" style="background: ....... etc....</div>'
The idea is transforming the buttons:
...into clickable buttons.
I guess the way to go is parse the HTML add clickable button and do "something" with ipywidgets jslink or so.