This guide explains how to display progress messages in real-time when running long computations in a notebook. When a notebook is in non-developer mode, displaying messages helps keep end users informed about ongoing processes.

Displaying Real-Time Messages

To provide real-time feedback to users, use the w_text_output widget in combination with the submit_widget_state() function. This approach ensures that messages appear dynamically as the process runs.

Example

from lplots.widgets.text import w_text_output
from lplots import submit_widget_state
import time

def run_long_process():
    # Display initial message
    w_text_output(content="Starting long-running process...", appearance={"message_box": "info"})
    submit_widget_state()
    
    # Simulate first long task
    time.sleep(2)
    w_text_output(content="Step 1 complete: Data preprocessing finished...", appearance={"message_box": "warning"})
    submit_widget_state()
    
    # Simulate second long task  
    time.sleep(2)
    w_text_output(content="Step 2 complete: Model training finished...", appearance={"message_box": "warning"})
    submit_widget_state()
    
    # Simulate final task
    time.sleep(2)
    w_text_output(content="✅ All processing complete!", appearance={"message_box": "success"})
    submit_widget_state()

# Run the example
run_long_process()

What it looks like: