UserScripts

class foxglove.layouts.UserScriptsPanel

Write custom data transformations in TypeScript.

For more information, see the documentation.

Example
import foxglove.layouts as fl

layout = fl.Layout(
    content=fl.UserScriptsPanel(
      config=fl.UserScriptsConfig(
        selected_node_id="script1",
      ),
    ),
    user_scripts={
        "script1": fl.UserScript(
            name="Hello World",
            source_code='''
// The ./types.ts module provides helper types for your Input events and messages.
import { Input, Message } from "./types.ts";

// Your script can output well-known message types, any of your custom message types, or
// complete custom message types.
//
// Use `Message` to access types from the schemas defined in your data source:
// type Twist = Message<"geometry_msgs/Twist">;
//
// Import from the @foxglove/schemas package to use foxglove schema types:
// import { Pose, LocationFix } from "@foxglove/schemas";
//
// Conventionally, it's common to make a _type alias_ for your script's output type
// and use that type name as the return type for your script function.
// Here we've called the type `Output` but you can pick any type name.
type Output = {
  hello: string;
};

// These are the topics your script "subscribes" to. Foxglove will invoke your script function
// when any message is received on one of these topics.
export const inputs = ["/input/topic"];

// Any output your script produces is "published" to this topic. Published messages are only visible within Foxglove, not to your original data source.
export const output = "/foxglove_script/output_topic";

// This function is called with messages from your input topics.
// The first argument is an event with the topic, receive time, and message.
// Use the `Input<...>` helper to get the correct event type for your input topic messages.
export default function script(event: Input<"/input/topic">): Output {
  return {
    hello: "world!",
  };
};
''',
        ),
    },
)
config: UserScriptsConfig
title: str | None = None

The title of the panel.

class foxglove.layouts.UserScriptsConfig

Configuration for the User Scripts panel.

auto_format_on_save: bool | None = None

Whether to automatically format the code on save.

selected_node_id: str | None = None

The ID of the selected script.