nova-trame API

Typing Classes

class nova.trame.utils.types.TrameTuple(expression: str, initial_value: Any = None)

Trame variable binding tuple.

Trame allows you to set component parameters dynamically by passing a tuple to most parameters. This tuple requires the following syntax: (expression, initial_value). expression is typically a JavaScript variable, but it can be any JavaScript expression that evaluates to a boolean value. initial_value should only used if your expression is a JavaScript variable.

classmethod create(expression: Any, initial_value: Any = None) Self

Turns a generic expression into a tuple suitable for binding a Trame component.

This is primarily intended for internal usage and makes aggressive assumptions about how to convert Python types to JavaScript expressions. If you are creating your own components with parameters that accept built-in types and Trame binding tuples, then it may prove useful to you either as is or subclassed.

Parameters:
  • expression (Any) – The content to turn into a JavaScript expression. If a string-type is provided, it is passed to Trame without modification.

  • initial_value (Any, optional) – The initial value to assign to expression. If set, expression must be a JavaScript variable.

expression: str

Alias for field number 0

initial_value: Any

Alias for field number 1

Theme Component

class nova.trame.ThemedApp(name: str = 'default', server: Server = None, vuetify_config_overrides: dict | None = None)

Automatically injects theming into your Trame application.

You should always inherit from this class when you define your Trame application.

__init__(name: str = 'default', server: Server = None, vuetify_config_overrides: dict | None = None) None

Constructor for the ThemedApp class.

Parameters:
  • name (str, optional) – The name of this app. You can pass this to get_app to retrieve an instance reference.

  • server (trame_server.core.Server, optional) – The Trame server to use. If not provided, a new server will be created.

  • vuetify_config_overrides (dict, optional) –

    Vuetify Configuration that will override anything set in our default configuration. You should only use this if you don’t want to use one of our predefined themes. If you just want to set your color palette without providing a full Vuetify configuration, then you can set use the following to only set the color palette used by our CompactTheme:

    {
        "primary": "#f00",
        "secondary": "#0f0",
        "accent": "#00f",
    }
    

Return type:

None

add_drawer(open: bool = False, **kwargs: Any) AbstractElement

Adds a navigation drawer to your layout.

You should always call this method from your application class that inherits from ThemedApp.

Parameters:
  • open (bool, optional) – If true then the drawer will be open when the user first opens the page.

  • **kwargs (Any, optional) – All other keyword arguments will be passed to the underlying VNavigationDrawer. Note that you cannot pass v_model as nova-trame manages this directly. Instead, please call the toggle_drawer method.

Returns:

A Trame element into which you can place your content using the with syntax.

Return type:

trame_client.widgets.core.AbstractElement

create_ui() VAppLayout

Creates the base UI into which you will inject your content.

You should always call this method from your application class that inherits from ThemedApp.

Return type:

trame_client.ui.core.AbstractLayout

download_file(filename: str, mimetype: str, content: bytes) None

Attempts to download a file via the browser to the user’s computer.

Note that this will do nothing if no client is connected to the Trame application when called.

Parameters:
  • filename (str) – The name of the file to be downloaded.

  • mimetype (str) – The MIME type of the content.

  • content (bytes) – The bytes to be included in the download.

Return type:

None

set_theme(theme: str | None, force: bool = True) None

Sets the theme of the application.

Parameters:
  • theme (str, optional) –

    The new theme to use. If the theme is not found, the default theme will be used. We currently only support a single theme:

    1. CompactTheme - A scientific theme with a smaller global font size and increased density compared to the default Vuetify theme.

  • force (bool, optional) – If True, the theme will be set even if the theme selection menu is disabled.

Return type:

None

toggle_drawer() None

Toggles the navigation drawer if enabled.

Layout Components

class nova.trame.view.layouts.GridLayout(columns: int = 1, height: int | str | None = None, width: int | str | None = None, halign: str | None = None, valign: str | None = None, gap: int | str | None = '0em', stretch: bool = False, **kwargs: Any)

Creates a grid with a specified number of columns.

__init__(columns: int = 1, height: int | str | None = None, width: int | str | None = None, halign: str | None = None, valign: str | None = None, gap: int | str | None = '0em', stretch: bool = False, **kwargs: Any) None

Constructor for GridLayout.

Parameters:
  • columns (int) – The number of columns in the grid.

  • height (optional[int | str]) – The height of this grid. If an integer is provided, it is interpreted as pixels. If a string is provided, the string is treated as a CSS value.

  • width (optional[int | str]) – The width of this grid. If an integer is provided, it is interpreted as pixels. If a string is provided, the string is treated as a CSS value.

  • halign (optional[str]) – The horizontal alignment of items in the grid. See MDN for available options.

  • valign (optional[str]) – The vertical alignment of items in the grid. See MDN for available options. Note that this parameter is ignored when stretch=True.

  • gap (optional[str]) – The gap to place between items (works both horizontally and vertically). Can be any CSS gap value (e.g. “4px” or “0.25em”). Defaults to no gap between items.

  • stretch (optional[bool]) – If True, then this layout component will stretch to attempt to fill the space of it’s parent container. Defaults to False.

  • kwargs (Any) – Additional keyword arguments to pass to html.Div.

Return type:

None

Examples

Basic usage:

with GridLayout(classes="mb-4", columns=2, halign="center", valign="center"):
    InputField(v_for="(item, index) in ['a', 'b', 'c', 'd']", text=("`${item} - ${index}`",), type="button")

Building a custom left-middle-right layout:

class LMRLayout:
    def __init__(self) -> None:
        with GridLayout(rows=1, columns=10, halign="center", valign="center"):
            self.left = html.Div(column_span=2)  # 20% width
            self.middle = html.Div(column_span=5)  # 50% width
            self.right = html.Div(column_span=3)  # 30% width

my_layout = LMRLayout()
with my_layout.left:
    vuetify.VBtn("Left Button")
add_child(child: AbstractElement | str) AbstractElement

Add a child to the grid.

Do not call this directly. Instead, use Trame’s with syntax, which will call this method internally. This method is documented here as a reference for the span parameters.

Parameters:
  • child (AbstractElement | str) – The child to add to the grid.

  • row_span (int) – The number of rows this child should span.

  • column_span (int) – The number of columns this child should span.

Return type:

None

Example

html.P("Grid cells can span multiple rows and/or columns.", classes="text-center")
with GridLayout(columns=3, height=400, halign="center", valign="center"):
    # The classes parameter is used to highlight the different cells for demonstration purposes.
    vuetify.VLabel("Item 1", classes="bg-primary h-100 w-100 justify-center")
    vuetify.VLabel("Item 2", classes="bg-secondary h-100 w-100 justify-center")
    vuetify.VLabel("Row Span", classes="bg-primary h-100 w-100 justify-center", row_span=2)
    vuetify.VLabel("Column Span", classes="bg-error h-100 w-100 justify-center", column_span=2)
    vuetify.VLabel(
        "Row and Column Span",
        classes="bg-secondary h-100 w-100 justify-center",
        row_span=2,
        column_span=3,
    )
class nova.trame.view.layouts.HBoxLayout(height: int | str | None = None, width: int | str | None = None, halign: str | None = None, valign: str | None = None, gap: int | str | None = '0em', vspace: int | str | None = '0em', stretch: bool = False, **kwargs: Any)

Creates an element that horizontally stacks its children.

__init__(height: int | str | None = None, width: int | str | None = None, halign: str | None = None, valign: str | None = None, gap: int | str | None = '0em', vspace: int | str | None = '0em', stretch: bool = False, **kwargs: Any) None

Constructor for HBoxLayout.

Parameters:
  • height (optional[int | str]) – The height of this box. If an integer is provided, it is interpreted as pixels. If a string is provided, the string is treated as a CSS value.

  • width (optional[int | str]) – The width of this box. If an integer is provided, it is interpreted as pixels. If a string is provided, the string is treated as a CSS value.

  • halign (optional[str]) – The horizontal alignment of items in the grid. See MDN for available options.

  • valign (optional[str]) – The vertical alignment of items in the grid. See MDN for available options.

  • gap (optional[str]) – The horizontal gap to place between items. Can be any CSS gap value (e.g. “4px” or “0.25em”). Defaults to no gap between items.

  • vspace (optional[str]) – The vertical gap to place between items. Can be any CSS gap value (e.g. “4px” or “0.25em”). Defaults to no gap between items.

  • stretch (optional[bool]) – If True, then this layout component will stretch to attempt to fill the space of it’s parent container. Defaults to False.

  • kwargs (Any) – Additional keyword arguments to pass to html.Div.

Return type:

None

Example

with HBoxLayout(classes="mb-4"):
    InputField(text="Button 1", type="button")
    InputField(text="Button 2", type="button")
    InputField(text="Button 3", type="button")
add_child(child: AbstractElement | str) AbstractElement

Add a child to the box.

Do not call this directly. Instead, use Trame’s with syntax, which will call this method internally. This method is documented here as a reference for the halign, stretch, and valign parameters.

Parameters:
  • child – The child to add to the grid.

  • halign (str) – NOTE: This parameter is valid at the box level but not for individual elements due to limitations in the CSS flexbox. Instead, you can use VSpacer to add horizontal space between elements.

  • stretch (bool) – Allows overriding the stretch parameter declared at the box level for a single child.

  • valign (str) – Allows overriding the vertical alignment declared at the box level for a single child.

Return type:

None

Example

html.P("Grid cells can span multiple rows and/or columns.", classes="text-center")
with GridLayout(columns=3, height=400, halign="center", valign="center"):
    # The classes parameter is used to highlight the different cells for demonstration purposes.
    vuetify.VLabel("Item 1", classes="bg-primary h-100 w-100 justify-center")
    vuetify.VLabel("Item 2", classes="bg-secondary h-100 w-100 justify-center")
    vuetify.VLabel("Row Span", classes="bg-primary h-100 w-100 justify-center", row_span=2)
    vuetify.VLabel("Column Span", classes="bg-error h-100 w-100 justify-center", column_span=2)
    vuetify.VLabel(
        "Row and Column Span",
        classes="bg-secondary h-100 w-100 justify-center",
        row_span=2,
        column_span=3,
    )
class nova.trame.view.layouts.VBoxLayout(height: int | str | None = None, width: int | str | None = None, halign: str | None = None, valign: str | None = None, gap: int | str | None = '0em', vspace: int | str | None = '0em', stretch: bool = False, **kwargs: Any)

Creates an element that vertically stacks its children.

__init__(height: int | str | None = None, width: int | str | None = None, halign: str | None = None, valign: str | None = None, gap: int | str | None = '0em', vspace: int | str | None = '0em', stretch: bool = False, **kwargs: Any) None

Constructor for VBoxLayout.

Parameters:
  • height (optional[int | str]) – The height of this box. If an integer is provided, it is interpreted as pixels. If a string is provided, the string is treated as a CSS value.

  • width (optional[int | str]) – The width of this box. If an integer is provided, it is interpreted as pixels. If a string is provided, the string is treated as a CSS value.

  • halign (optional[str]) – The horizontal alignment of items in the grid. See MDN for available options.

  • valign (optional[str]) – The vertical alignment of items in the grid. See MDN for available options.

  • gap (optional[str]) – The horizontal gap to place between items. Can be any CSS gap value (e.g. “4px” or “0.25em”). Defaults to no gap between items.

  • vspace (optional[str]) – The vertical gap to place between items. Can be any CSS gap value (e.g. “4px” or “0.25em”). Defaults to no gap between items.

  • stretch (optional[bool]) – If True, then this layout component will stretch to attempt to fill the space of it’s parent container. Defaults to False.

  • kwargs (Any) – Additional keyword arguments to pass to html.Div.

Return type:

None

Example

with VBoxLayout(classes="mb-4"):
    InputField(text="Button 1", type="button")
    InputField(text="Button 2", type="button")
    InputField(text="Button 3", type="button")
add_child(child: AbstractElement | str) AbstractElement

Add a child to the box.

Do not call this directly. Instead, use Trame’s with syntax, which will call this method internally. This method is documented here as a reference for the halign, stretch, and valign parameters.

Parameters:
  • child – The child to add to the grid.

  • halign (str) – Allows overriding the horizontal alignment declared at the box level for a single child.

  • stretch (bool) – Allows overriding the stretch parameter declared at the box level for a single child.

  • valign (str) – NOTE: This parameter is valid at the box level but not for individual elements due to limitations in the CSS flexbox. Instead, you can use VSpacer to add vertical space between elements.

Return type:

None

Example

html.P("Grid cells can span multiple rows and/or columns.", classes="text-center")
with GridLayout(columns=3, height=400, halign="center", valign="center"):
    # The classes parameter is used to highlight the different cells for demonstration purposes.
    vuetify.VLabel("Item 1", classes="bg-primary h-100 w-100 justify-center")
    vuetify.VLabel("Item 2", classes="bg-secondary h-100 w-100 justify-center")
    vuetify.VLabel("Row Span", classes="bg-primary h-100 w-100 justify-center", row_span=2)
    vuetify.VLabel("Column Span", classes="bg-error h-100 w-100 justify-center", column_span=2)
    vuetify.VLabel(
        "Row and Column Span",
        classes="bg-secondary h-100 w-100 justify-center",
        row_span=2,
        column_span=3,
    )

General Purpose Components

class nova.trame.view.components.InputField(v_model: str | Tuple | None = None, debounce: int | Tuple = -1, throttle: int | Tuple = -1, type: str = 'text', **kwargs: Any)

Factory class for generating Vuetify input components.

static __new__(cls, v_model: str | Tuple | None = None, debounce: int | Tuple = -1, throttle: int | Tuple = -1, type: str = 'text', **kwargs: Any) AbstractElement

Constructor for InputField.

For all parameters, tuples have a special syntax. See TrameTuple for a description of it.

Parameters:
  • v_model (Union[str, Tuple], optional) – The v-model for this component. If this references a Pydantic configuration variable, then this component will attempt to load a label, hint, and validation rules from the configuration for you automatically.

  • debounce (Union[int, Tuple], optional) – Number of milliseconds to wait after the last user interaction with this field before attempting to update the Trame state. If set to 0, then no debouncing will occur. If set to -1, then the environment variable NOVA_TRAME_DEFAULT_DEBOUNCE will be used to set this (defaults to 0). See the Lodash Docs for details.

  • throttle (Union[int, Tuple], optional) – Number of milliseconds to wait between updates to the Trame state when the user is interacting with this field. If set to 0, then no throttling will occur. If set to -1, then the environment variable NOVA_TRAME_DEFAULT_THROTTLE will be used to set this (defaults to 0). See the Lodash Docs for details.

  • type (str) –

    The type of input to create. This can be any of the following:

    • autocomplete - Produces a dropdown menu that supports autocompletion as the user types. Items can be automatically populated (see select option for details).

    • autoscroll - Produces a textarea that automatically scrolls to the bottom as new content is added.

    • button - Note that all named arguments (e.g. v_model) will be ignored when using this. kwargs can still be used to customize the button.

    • checkbox

    • combobox - Produces a dropdown menu that supports autocompletion as the user types and allows users to add new items. Items can be automatically populated (see select option for details).

    • file

    • input

    • number

    • otp

    • radio - Produces a radio button group. Note that this accepts an additional parameter items that expects a list of dictionaries with the following format: { title: ‘Item 1’, value: ‘item_1’ }.

    • range-slider

    • select - Produces a dropdown menu. This menu can have items automatically populated if the v_model is connected to a Pydantic field that uses an Enum type. Otherwise, you must specify the items parameter to InputField.

      class DropdownOptions(str, Enum):
          item_a = "item_a"
          item_b = "item_b"
          item_c = "item_c"
      
      class Dropdown(BaseModel):
          enum_field: DropdownOptions = Field(default=DropdownOptions.item_a)
          str_field: str = Field(default="test")
      
      dropdown = Dropdown()
      
      InputField(v_model="dropdown.enum_field", type="select")
      
    • slider

    • switch

    • textarea

    Any other value will produce a text field with your type used as an HTML input type attribute. Note that parameter does not support binding since swapping field types dynamically produces a confusing user experience.

  • **kwargs

    All other arguments will be passed to the underlying Trame Vuetify component. The following example would set the auto_grow and label attributes on VTextarea:

    InputField(type="textarea", auto_grow=True, label="Text Area")
    

Returns:

The Vuetify input component.

Return type:

trame_client.widgets.core.AbstractElement

class nova.trame.view.components.PersistentDialog(v_model: str | Tuple, close_on_escape: bool = True, **kwargs: Any)

Component for creating a Vuetify dialog that closes on the escape key but not outside clicks.

property state: State

Return the associated server state

class nova.trame.view.components.RemoteFileInput(v_model: str | Tuple, allow_files: bool | Tuple = True, allow_folders: bool | Tuple = False, base_paths: Iterable[str] | str | None = None, dialog_props: dict[str, Any] | None = None, extensions: Iterable[str] | str | None = None, input_props: dict[str, Any] | None = None, return_contents: bool | Tuple = False, use_bytes: bool | Tuple = False)

Generates a file selection dialog for picking files off of the server.

You cannot use typical Trame with syntax to add children to this.

__init__(v_model: str | Tuple, allow_files: bool | Tuple = True, allow_folders: bool | Tuple = False, base_paths: Iterable[str] | str | None = None, dialog_props: dict[str, Any] | None = None, extensions: Iterable[str] | str | None = None, input_props: dict[str, Any] | None = None, return_contents: bool | Tuple = False, use_bytes: bool | Tuple = False) None

Constructor for RemoteFileInput.

For all parameters, tuples have a special syntax. See TrameTuple for a description of it.

Parameters:
  • v_model (Union[str, Tuple]) – The v-model for this component. If this references a Pydantic configuration variable, then this component will attempt to load a label, hint, and validation rules from the configuration for you automatically.

  • allow_files (Union[bool, Tuple], optional) – If true, the user can save a file selection.

  • allow_folders (Union[bool, Tuple], optional) – If true, the user can save a folder selection.

  • base_paths (Union[Iterable[str], str], optional) – Only files under these paths will be shown. Typical Trame binding syntax doesn’t work here as tuples are interpreted as literal extensions to filter with. Instead, you can pass a string with a JavaScript expression to bind this parameter.

  • dialog_props (Dict[str, Any], optional) – Props to be passed to VDialog.

  • extensions (Union[Iterable[str], str], optional) – Only files with these extensions will be shown by default. The user can still choose to view all files. Typical Trame binding syntax doesn’t work here as tuples are interpreted as literal extensions to filter with. Instead, you can pass a string with a JavaScript expression to bind this parameter.

  • input_props (Dict[str, Any], optional) – Props to be passed to InputField.

  • return_contents (Union[bool, Tuple], optional) – If true, then the v_model will contain the contents of the file. If false, then the v_model will contain the path of the file. Defaults to false.

  • use_bytes (Union[bool, Tuple], optional) – If true, then the file contents will be treated as bytestreams when calling decode_file.

Return type:

None

open_dialog() None

Programmatically opens the dialog for selecting a file.

select_file(value: str) None

Programmatically set the v_model value.

class nova.trame.view.components.FileUpload(v_model: str | Tuple, base_paths: Iterable[str] | str | None = None, extensions: Iterable[str] | str | None = None, label: str = '', return_contents: bool | Tuple = True, show_server_files: bool | Tuple = True, use_bytes: bool | Tuple = False, **kwargs: Any)

Component for uploading a file from either the user’s filesystem or the server filesystem.

__init__(v_model: str | Tuple, base_paths: Iterable[str] | str | None = None, extensions: Iterable[str] | str | None = None, label: str = '', return_contents: bool | Tuple = True, show_server_files: bool | Tuple = True, use_bytes: bool | Tuple = False, **kwargs: Any) None

Constructor for FileUpload.

For all parameters, tuples have a special syntax. See TrameTuple for a description of it.

Parameters:
  • v_model (Union[str, Tuple]) – The state variable to set when the user uploads their file. The state variable will contain a latin1-decoded version of the file contents. If your file is binary or requires a different string encoding, then you can call encode(‘latin1’) on the file contents to get the underlying bytes.

  • base_paths (Union[Iterable[str], str], optional) – Passed to RemoteFileInput. Typical Trame binding syntax doesn’t work here as tuples are interpreted as literal extensions to filter with. Instead, you can pass a string with a JavaScript expression to bind this parameter.

  • extensions (Union[Iterable[str], str], optional) – Restricts the files shown to the user to files that end with one of the strings in the list. Typical Trame binding syntax doesn’t work here as tuples are interpreted as literal extensions to filter with. Instead, you can pass a string with a JavaScript expression to bind this parameter.

  • label (str, optional) – The text to display on the upload button.

  • return_contents (Union[bool, Tuple], optional) – If true, the file contents will be stored in v_model. If false, a file path will be stored in v_model. Defaults to true.

  • show_server_files (Union[bool, Tuple], optional) – If true, then the “From Server” option to select a file will be shown. Defaults to true.

  • use_bytes (Union[bool, Tuple], optional) – If true, then files uploaded from the local machine will contain bytes rather than text.

  • **kwargs – All other arguments will be passed to the underlying Button component.

Return type:

None

select_file(value: str) None

Programmatically set the RemoteFileInput path.

Parameters:

value (str) – The new value for the RemoteFileInput.

Return type:

None

property state: State

Return the associated server state

class nova.trame.view.components.DataSelector(v_model: str | Tuple, directory: str | Tuple, action: str | Callable = '', action_icon: str | Tuple = '', action_visible: bool | Tuple = True, clear_selection_on_directory_change: bool | Tuple = True, extensions: List[str] | Tuple | None = None, prefix: str | Tuple = '', subdirectory: str | Tuple = '', refresh_rate: int | Tuple = 30, select_strategy: str | Tuple = 'all', show_selected_files: bool | Tuple = True, **kwargs: Any)

Allows the user to select datafiles from the server.

__init__(v_model: str | Tuple, directory: str | Tuple, action: str | Callable = '', action_icon: str | Tuple = '', action_visible: bool | Tuple = True, clear_selection_on_directory_change: bool | Tuple = True, extensions: List[str] | Tuple | None = None, prefix: str | Tuple = '', subdirectory: str | Tuple = '', refresh_rate: int | Tuple = 30, select_strategy: str | Tuple = 'all', show_selected_files: bool | Tuple = True, **kwargs: Any) None

Constructor for DataSelector.

For all parameters, tuples have a special syntax. See TrameTuple for a description of it.

Parameters:
  • v_model (Union[str, Tuple]) – The name of the state variable to bind to this widget. The state variable will contain a list of the files selected by the user.

  • directory (Union[str, Tuple]) – The top-level folder to expose to users. Only contents of this directory and its children will be exposed to users.

  • action (Union[str, Callable], optional) – When set, adds a button next to each datafile title that triggers the provided callback when clicked. This callback will be passed a dictionary containing the selected file’s available information.

  • action_icon (Union[str, Tuple], optional) – Sets the icon for each action button. A list of available icons can be found here.

  • action_visible (Union[bool, Tuple], optional) – Adds a condition to use for checking if the action button should be shown for each datafile. By default, all datafiles will show the action button.

  • clear_selection_on_directory_change (Union[bool, Tuple], optional) – Whether or not to clear the selected files when the directory is changed.

  • extensions (Union[List[str], Tuple], optional) – A list of file extensions to restrict selection to. If unset, then all files will be shown.

  • prefix (Union[str, Tuple], optional) – Deprecated. Please refer to the subdirectory parameter.

  • subdirectory (Union[str, Tuple], optional) – A subdirectory within the selected top-level folder to show files. If not specified as a string, the user will be shown a folder browser and will be able to see all files in the selected top-level folder.

  • refresh_rate (Union[int, Tuple], optional) – The number of seconds between attempts to automatically refresh the file list. Set to zero to disable this feature. Defaults to 30 seconds.

  • select_strategy (Union[str, Tuple], optional) – The selection strategy to pass to the VDataTable component. If unset, the all strategy will be used.

  • show_selected_files (Union[bool, Tuple], optional) – If true, then the currently selected files will be shown to the user below the directory and file selection widgets.

  • **kwargs – All other arguments will be passed to the underlying VDataTable component.

Return type:

None

property state: State

Return the associated server state

class nova.trame.view.utilities.local_storage.LocalStorageManager(ctrl: Controller)

Allows manipulation of window.localStorage from your Python code.

LocalStorageManager requires a Trame layout to exist in order to work properly. Because of this, it’s strongly recommended that you don’t use this class directly. Instead, ThemedApp automatically creates an instance of this class and stores it in ThemedApp.local_storage, through which it can safely be used.

__init__(ctrl: Controller) None

Constructor for the LocalStorageManager class.

Parameters:

ctrl (trame_server.core.Controller) – The Trame controller.

Return type:

None

async get(key: str) str | None

Gets the value of a key from window.localStorage.

You cannot call this from the main Trame coroutine because this waits on a response from the browser that must be processed by the main coroutine. Instead, you should call this from another thread or coroutine, typically with asyncio.create_task.

Parameters:

key (str) – The key to get the value of.

Returns:

The value of the key from window.localStorage.

Return type:

Optional[str]

remove(key: str) None

Removes a key from window.localStorage.

Parameters:

key (str) – The key to remove.

Return type:

None

set(key: str, value: Any) None

Sets the value of a key in window.localStorage.

Parameters:
  • key (str) – The key to set the value of.

  • value (Any) – The value to set. This value will be coerced to a string before being stored.

Return type:

None

Job Management Components

class nova.trame.view.components.ExecutionButtons(id: str, stop_btn: bool | Tuple = False, download_btn: bool | Tuple = False)

Execution buttons class. Adds Run/Stop/Cancel/Download buttons to the view.

This is intended to be used with the nova-galaxy ToolRunner.

__init__(id: str, stop_btn: bool | Tuple = False, download_btn: bool | Tuple = False) None

Constructor for ExecutionButtons.

For all parameters, tuples have a special syntax. See TrameTuple for a description of it.

Parameters:
  • id (str) – Component id. Should be used consistently with ToolRunner and other components. Note that this parameter does not support Trame bindings.

  • stop_btn (Union[bool, Tuple]) – Display stop button.

  • download_btn (Union[bool, Tuple]) – Display download button.

Return type:

None

class nova.trame.view.components.ProgressBar(id: str)

Progress bar class. Adds progress bar that displays job status to the view.

This is intended to be used with the nova-galaxy ToolRunner.

__init__(id: str) None

Constructor for ProgressBar.

Parameters:

id (str) – Component id. Should be used consistently with ToolRunner and other components. Note that this parameter does not support Trame bindings.

Return type:

None

class nova.trame.view.components.ToolOutputWindows(id: str)

Tool outputs class. Displays windows with tool stdout/stderr.

This is intended to be used with the nova-galaxy ToolRunner.

__init__(id: str) None

Constructor for ToolOutputWindows.

Parameters:

id (str) – Component id. Should be used consistently with ToolRunner and other components. Note that this parameter does not support Trame bindings.

Return type:

None

Visualization Components

class nova.trame.view.components.visualization.Interactive2DPlot(figure: Chart | None = None, **kwargs: Any)

Creates an interactive 2D plot in Trame using Vega.

Trame provides two primary mechanisms for composing 2D plots: Plotly and Vega-Lite/Altair. If you only need static plots or basic browser event handling, then please use these libraries directly.

If you need to capture complex front-end interactions, then you can use our provided Interactive2DPlot widget that is based on Vega-Lite. This uses the same API as Trame’s vega.Figure, except that it will automatically sync Vega’s signal states as the user interacts with the plot.

The following allows the user to select a region of the plot and tracks the selected region in Python:

from altair import Chart, selection_interval
from vega_datasets import data

brush = selection_interval(name="brush")
chart = (
    Chart(data.cars())
    .mark_circle()
    .encode(x="Horsepower:Q", y="Miles_per_Gallon:Q", color="Origin:N")
    .add_params(brush)
)
plot = Interactive2DPlot(figure=chart)
__init__(figure: Chart | None = None, **kwargs: Any) None

Constructor for Interactive2DPlot.

Parameters:
Return type:

None

get_signal_state(name: str) Any

Retrieves a Vega signal’s state by name.

Parameters:

name (str) – The name of the signal to retrieve.

Returns:

The current value of the Vega signal.

Return type:

Any

update(figure: Chart | None = None, **kwargs: Any) None

Update the Figure with new content

Parameters:

figure – Altair chart object

class nova.trame.view.components.visualization.MatplotlibFigure(figure: Figure | None = None, webagg: bool = False, **kwargs: Any)

Creates an interactive Matplotlib Figure using the WebAgg backend.

By default, this will leverage the built-in Trame widget for Matplotlib support. This built-in widget can display poor performance for detailed plots due to it being locked into using SVG rendering.

If you experience this, then you can use the webagg parameter to enable the WebAgg backend for Matplotlib. This will switch to server-side rendering leveraging the Anti-Grain Geometry engine.

my_figure = matplotlib.figure.Figure()
MatplotlibFigure(my_figure)  # Display SVG-based plot in Trame
MatplotlibFigure(my_figure, webagg=True)  # Display WebAgg-based plot in Trame
__init__(figure: Figure | None = None, webagg: bool = False, **kwargs: Any) None

Creates a Matplotlib figure in the Trame UI.

Parameters:
  • figure (matplotlib.figure.Figure, optional) – Initial Matplotlib figure.

  • webagg (bool, optional) – If true, then the WebAgg backend for Matplotlib is used. If not, then the default Trame matplotlib plugin is used. Note that this parameter does not supporting Trame bindings since the user experiences are fundamentally different between the two options and toggling them is not considered a good idea by the author of this component.

  • kwargs

    Arguments to be passed to AbstractElement

Return type:

None

update(figure: Figure | None = None, skip_resize: bool = False) None

Update the figure to show.

Parameters:

figure – Matplotlib figure object

ORNL-only components

class nova.trame.view.components.ornl.NeutronDataSelector(v_model: str | Tuple, allow_custom_directories: bool | Tuple = False, clear_selection_on_experiment_change: bool | Tuple = True, data_source: Literal['filesystem', 'oncat'] = 'filesystem', facility: str | Tuple = '', instrument: str | Tuple = '', experiment: str | Tuple = '', show_experiment_filters: bool | Tuple = True, show_selected_files: bool | Tuple = True, extensions: List[str] | Tuple | None = None, projection: List[str] | Tuple | None = None, subdirectory: str | Tuple = '', refresh_rate: int | Tuple = 30, select_strategy: str | Tuple = 'all', **kwargs: Any)

Allows the user to select datafiles from an IPTS experiment.

__init__(v_model: str | Tuple, allow_custom_directories: bool | Tuple = False, clear_selection_on_experiment_change: bool | Tuple = True, data_source: Literal['filesystem', 'oncat'] = 'filesystem', facility: str | Tuple = '', instrument: str | Tuple = '', experiment: str | Tuple = '', show_experiment_filters: bool | Tuple = True, show_selected_files: bool | Tuple = True, extensions: List[str] | Tuple | None = None, projection: List[str] | Tuple | None = None, subdirectory: str | Tuple = '', refresh_rate: int | Tuple = 30, select_strategy: str | Tuple = 'all', **kwargs: Any) None

Constructor for DataSelector.

For all parameters, tuples have a special syntax. See TrameTuple for a description of it.

Parameters:
  • v_model (Union[str, Tuple]) – The name of the state variable to bind to this widget. The state variable will contain a list of the files selected by the user.

  • action (Union[str, Callable], optional) – When set, adds a button next to each datafile title that triggers the provided callback when clicked. This callback will be passed a dictionary containing the selected file’s available information.

  • action_icon (Union[str, Tuple], optional) – Sets the icon for each action button. A list of available icons can be found here.

  • action_visible (Union[bool, Tuple], optional) – Adds a condition to use for checking if the action button should be shown for each datafile. By default, all datafiles will show the action button.

  • allow_custom_directories (Union[bool, Tuple], optional) – Whether or not to allow users to provide their own directories to search for datafiles in. Ignored if the facility parameter is set.

  • clear_selection_on_experiment_change (Union[bool, Tuple], optional) – Whether or not to clear the selected files when the user changes the facility, instrument, or experiment.

  • data_source (Literal["filesystem", "oncat"], optional) – The source from which to pull datafiles. Defaults to “filesystem”. If using ONCat, you will need to set the following environment variables for local development: ONCAT_CLIENT_ID and ONCAT_CLIENT_SECRET. Note that this parameter does not supporting Trame bindings. If you need to swap between the options, please create two instances of this class and switch between them using a v_if or a v_show.

  • facility (Union[str, Tuple], optional) – The facility to restrict data selection to. Options: HFIR, SNS

  • instrument (Union[str, Tuple], optional) – The instrument to restrict data selection to. Please use the instrument acronym (e.g. CG-2).

  • experiment (Union[str, Tuple], optional) – The experiment to restrict data selection to.

  • show_experiment_filters (Union[bool, Tuple], optional) – If false, then the facility, instrument, and experiment selection widgets will be hidden from the user. This is only intended to be used when all of these parameters are fixed or controlled by external widgets.

  • show_selected_files (Union[bool, Tuple], optional) – If true, then the currently selected files will be shown to the user below the directory and file selection widgets.

  • extensions (Union[List[str], Tuple], optional) – A list of file extensions to restrict selection to. If unset, then all files will be shown.

  • projection (Union[List[str], Tuple], optional) – Sets the projection argument when pulling data files via pyoncat. Please refer to the ONCat documentation for how to use this. This should only be used with data_source=”oncat”.

  • subdirectory (Union[str, Tuple], optional) – A subdirectory within the user’s chosen experiment to show files. If not specified as a string, the user will be shown a folder browser and will be able to see all files in the experiment that they have access to.

  • refresh_rate (Union[str, Tuple], optional) – The number of seconds between attempts to automatically refresh the file list. Set to zero to disable this feature. Defaults to 30 seconds.

  • select_strategy (Union[str, Tuple], optional) – The selection strategy to pass to the VDataTable component. If unset, the all strategy will be used.

  • **kwargs

    All other arguments will be passed to the underlying VDataTable component.

Return type:

None