01: Hello World
The smallest possible Weaverlet app. A single
WeaverletComponentsubclass with a layout-onlyget_layoutmethod, handed toWeaverletApp. No callbacks, no IDs, no composition. Just to confirm the install works and to see the shape of a component.
The script
from weaverlet.base import WeaverletComponent, WeaverletApp
from dash import html
class HelloWorldComponent(WeaverletComponent):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def get_layout(self):
return html.Div(f'hello world!')
helloworld_component = HelloWorldComponent()
wapp = WeaverletApp(root_component=helloworld_component)
wapp.app.run(port=8086)
Expected output
Running the app opens http://localhost:8086 showing a blank white page with the text "hello world!".
Notes
- Every Weaverlet app needs at least one
WeaverletComponentsubclass withget_layoutimplemented and a singleWeaverletApp(root_component=...)call. wapp.app.run(...)is the modern Dash 4 entry point. neverapp.run_server(...), which was removed in Dash 4.- The script uses the legacy import
from weaverlet.base import .... The modern equivalent isfrom weaverlet import WeaverletComponent, WeaverletApp: both work in 0.3+.
Try it locally
pip install weaverlet
# Save the script above as helloworld.py
python helloworld.py