3

I'm wondering if there is a way to display HTML text that can update itself in Python with Jupyter Notebooks.

In other words, I want to be able to say:

<p>Hi there!</p> 

and then....

<p>Go away!</p> 

but instead of producing two lines of text, I want the first line to be changed into the second.

Any ways to achieve this? (I assume it requires some kind of JS, but I'm not sure how to do that)...

EDIT:

I originally asked how to update Python text like: print("Hello World") but I specifically want to update HTML text because I want to be able to apply CSS properties to the text.

4
  • Have you looked at jupyter widgets? You might have good luck with the HTML widget: ipywidgets.readthedocs.io/en/latest/examples/… Commented Mar 3, 2018 at 21:35
  • Yeah I've looked into Ipython widgets, unfortunately there does not seem to be a good way to change CSS properties of the widget text so you can't really change the size, color, etc. Commented Mar 5, 2018 at 19:31
  • You can generate arbitrary HTML output with the html widget, which is what your question indicates. Commented Mar 7, 2018 at 17:44
  • Change colour of text.... stackoverflow.com/questions/38684791/… Commented Apr 21, 2019 at 14:30

1 Answer 1

5

This worked for me:

from IPython.display import display import ipywidgets as widgets import time out = widgets.HTML() display(out) out.value="<p>Hi there!</p>" time.sleep(1) out.value = "<p>Go away!</p>" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.