Skip to main content


Wave ships with a growing library of cards and components for assembling user interfaces. For most apps, the built-in components can be adequate. They're designed to work well with each other, with consistent typography, layout and theming; and the library of components keeps expanding with each new release.

However, no matter how comprehensive the Wave library gets over time, there will be situations where an app needs to use external Javascript components to supplement Wave's capabilities, like custom visualizations, UI enhancements, and graphics.

Wave 0.16+ allows importing and using third-party Javascript libraries on a page. This provides an escape-hatch of sorts, allowing you to add UI capabilities that are not yet possible with stock Wave.

Basic Usage

The simplest way to run custom Javascript code on a page is to use an inline script (ui.inline_script()):['meta'] = ui.meta_card(box='', script=ui.inline_script('alert("Hello World!");'))

To execute additional bits of Javascript code, set the meta_card's script property again:['meta'].script = ui.inline_script('console.log("One Mississippi");')['meta'].script = ui.inline_script('console.log("Two Mississippi");')['meta'].script = ui.inline_script('console.log("Three Mississippi");')

Passing scripts to ui.meta_card() dynamically imports external Javascript libraries.

Import a library:['meta'] = ui.meta_card(box='', scripts=[ui.script('')])

Import multiple libraries:['meta'] = ui.meta_card(box='', scripts=[

Import and use a library:['meta'] = ui.meta_card(
# Load anime.js
# The Javascript code for this script.
# Execute this script only if the 'anime' library is available.
# Execute this script only if the 'animation' element is available.
)['example'] = ui.markup_card(
box='1 1 10 8',
content='<div id="animation"/>',

In the above example, we create an empty div HTML element on the page, load an animation library (anime.js), add a bit of Javascript to animate the div element. To tie things together correctly, we pass two additional arguments to ui.inline_script():

  • The requires argument ensures that the library we intend to use (in this case, anime.js) is downloaded, imported, and ready to use.
  • The targets argument ensures that the HTML element the scripts operates on (in this case, the div element named animation), is available on the page. CSS selectors can also be used to identify target elements.

Handling Events

In most cases, when employing custom Javascript libraries, you'll want to handle and transmit events from the library to your app. To do this, use the Javascript function wave.emit():

// Javascript
wave.emit('event_source', 'event_name', event_data);

You can then access this information in your app using:

# Python
event_data =

For example, emitting an event using wave.emit('graph', 'node_clicked', 42) in Javascript will set to 42 in Python.

All three arguments to wave.emit() are arbitrary. In the above example, we use:

  • graph to indicate the source of the event.
  • node_clicked to indicate the type of event.
  • the third argument can be a string, number, boolean or any complex structure, like { foo: 'bar', qux: 42 }.

Here's a complete, minimal example that prints mouse coordinates each time you click on a page.

from h2o_wave import main, app, Q, ui

async def serve(q: Q):
if not q.client.initialized:['meta'] = ui.meta_card(box='', script=ui.inline_script(
# Handle and transmit event
'window.onclick = (e) => wave.emit("window", "clicked", { x: e.clientX, y: e.clientY });'
q.client.initialized = True
# Capture event
click =
if click:
print(click.x, click.y)



You can play with more examples in the Wave Tour as well.