Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Jupyter Notebook support

Introduction

The notebook submodules (immapp.nb and hello_imgui.nb) provide convenient functions for the usage in a local jupyter notebook, with two main modes:

  • blocking mode: other cells cannot be run in parallel. A screenshot is displayed after the application exits.

  • non-blocking mode: other cells can be run in parallel. The application window updates live.

Blocking mode

API

immapp.nb.run and hello_imgui.nb.run functions will run a GUI application, wait for it to exit, and display a screenshot of the final application screen in the cell output.

During the application execution, other cells cannot be run.

Parameters

immapp.nb.run and hello_imgui.nb.run accept the same parameters as immapp.run and hello_imgui.run, respectively.

Optional additional parameters to controls the screenshot size (choose only one of the two):

  • thumbnail_ratio: (default=1.0) You can use it to change the size of the thumbnail. Passing 0.5 will create a thumbnail half the width of the window.

  • thumbnail_height: (default=0) You can use it to set a fixed height for the thumbnail (in pixels). If 0, the height is computed from the app window size.

Example

The example cell below demonstrates the blocking mode using immapp.nb.run. It shows a sinusoidal curve that can be adjusted with a slider. After closing the application window, a screenshot of the final state is displayed in the cell output.

<IPython.core.display.Image object>

Non blocking mode

(Since v1.92.6)

API

start

  • immapp.nb.start and hello_imgui.nb.start will run a GUI application, display it in a top-most window on top of the browser.

Other cells can be run while the application is running. The application window will update live.

Note: these function return an asyncio.Task, which may be awaited or managed using asyncio.

Parameters

immapp.nb.start and hello_imgui.nb.start accept the same parameters as immapp.start and hello_imgui.start, respectively.

Optional additional parameter: top_most to control if the application window should stay on top of other windows.

is_running

  • immapp.nb.is_running and hello_imgui.nb.is_running return True if the application is running, False otherwise.

stop

  • immapp.nb.stop and hello_imgui.nb.stop will stop the running application.

Note: If other cells are running while the application is running, they should call await asyncio.sleep(0) periodically to allow the application to update.

Example

Start the application

The cell below demonstrates the non-blocking mode using immapp.nb.start. It runs the same application as before (a sinusoidal curve that can be adjusted with a slider). You can modify the frequency while the application is running by changing the value of the FREQ variable in another cell.

When you run it, the cell exits immediately, but the GUI application continues to show and to be interactive (you can then run other cells while the application is running).

Note: since, immapp.nb.start returns an asyncio.Task, you can see that the cell output shows the task information (Task pending, ...).

<Task pending name='Task-35' coro=<run_async() running at /Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/immapp/run_async_overloads.py:63>>

Interact while the application is running

The cell below shows that it is possible to modify the frequency via code while the application is running, and the curve updates live.

Check if the application is running

The cells below can be used to check if the application is running

True

Stop the application

Video demonstration

Demonstration of the non-blocking mode in a Jupyter notebook.

Example: Real-Time Data Stream Simulation

This example simulates a live data stream that continuously updates, like you might see in a monitoring dashboard or during ML training.

Start the GUI

The cell below instantiate the application data (stream_data) and starts a GUI application that displays the live data stream.

✓ Streaming GUI started!
✓ Run the next cell to start the data stream.

Simulate Data Stream

The cell below simulates a data stream: this will add data points while the GUI displays them in real-time.

  • The GUI is already running above (in an asyncio task)

  • So, we define another asyncio task to add data points (stream_data_loop below), and we run it in async way.

This cell will run for 5 seconds: while it runs, you should see the GUI updating live with new data points.

Starting data stream... (will run for 10 seconds)
✓ Stream finished. Final count: 492 points

Video demonstration

Demonstration of the real-time data stream simulation in a Jupyter notebook.

Example: Real-Time AI Training and tuning

Video demonstration on youtube

Real-Time AI Training and tuning with Dear ImGui Bundle in Jupyter Notebooks

Links to notebooks