A Retool custom component that displays hierarchical tree data and automatically exports its HTML as a base64 image.
- Display hierarchical tree structures with expandable/collapsible nodes
- Support for custom icons and node data
- Automatic base64 image generation when tree data changes
- Manual export button for on-demand image generation
- Clean, modern UI with hover effects
- Navigate to the component directory:
cd tree_component- Install dependencies:
npm install- Run in development mode:
npm run dev- Deploy to Retool:
npm run deployThe component expects tree data in the following format:
[
{
"id": "1",
"label": "Root Node",
"icon": "📁",
"children": [
{
"id": "1-1",
"label": "Child Node 1",
"icon": "📄",
"children": []
},
{
"id": "1-2",
"label": "Child Node 2",
"icon": "📄"
}
]
}
]-
treeData (array): The hierarchical tree data structure
id(string, required): Unique identifier for the nodelabel(string, required): Display label for the nodeicon(string, optional): Emoji or text icon to displaychildren(array, optional): Array of child nodesdata(object, optional): Additional custom data
-
base64Image (string, readonly): The generated base64-encoded image of the tree
- imageGenerated: Triggered when a new base64 image is generated (automatically or manually)
- Add the Tree Component to your Retool app
- Set the
treeDataproperty with your hierarchical data - Access the generated image via
{{ treeComponent.base64Image }} - Use the
imageGeneratedevent to trigger additional actions
The component automatically generates a base64 image whenever the tree data changes. You can also manually trigger export using the "Export as Image" button.
The base64 image can be:
- Displayed in an Image component:
{{ treeComponent.base64Image }} - Downloaded as a file
- Sent to an API
- Stored in a database
npm run dev- Run in development mode with hot reloadnpm run deploy- Deploy to Retool
MIT