Cheatsheet
The working application below captures the fundamentals of trame in less than 45 lines. Consider this as a cheatsheet on how to use trame as it is mostly self explanatory.
from trame.app import get_server # Entry point to trame |
Results
Explanatory Details
State
Read a variable from shared state:
value = state.var_name |
Write a variable to shared state:
state.var_name = value |
Write several variables at once to the shared state:
state.update({ |
Bind a method/function to a state variable change:
|
Specify an initial value for a UI variable. Use a tuple to define the value of a given attribute, where the first entry is a string with the variable name and the second entry is its initial value.
vuetify.VTextField(v_model=("var_name", "initial value")) |
Provide a JavaScript expression as an attribute value. We still provide a tuple but with no initial value.
vuetify.VTextField(value=("'Hello' + var_name", )) |
Method binding
Methods can be passed to the events attribute of your UI elements. By default, the function will be called with no arguments.
If you want to control its arguments you can use a tuple where the second entry represents the args and the third represents the kwargs. If you only want to provide args without kwargs, just provide a tuple with 2 entries. $event is a reserved name to represent the event object.
vuetify.VBtn("Click me", click=ctrl.do_something)) |
Controller
The trame controller is just a dynamic container for methods or functions that can be set or get in either order.
vuetify.VBtn("Click me", click=ctrl.do_something) |
Life Cycle
- on_server_ready : All protocols initialized and available for the client to connect.
- on_client_connected : Connection established to server.
- on_client_exited : Linked to browser “beforeunload” event.
- on_server_exited : Trame is exiting its event loop.
- on_server_reload : If callback registered it is used to reload server side modules.
|
Conclusion and Next Steps
At this point the fundamentals of trame have been presented. To build fully-fledged applications, the next steps are to learn the various components available for displaying 3D graphics, charts, maps and more. For more details, please refer to the tutorial or API.
Trame is a powerful Pyton-based integration framework for creating visual analytics applications. From prototypes to professional applications, trame offers an innovative approach to “write once and run anywhere” through applications that run from a desktop to a cloud service using a standard web browser.