Custom Components
Learn how to render custom components in Semaphor dashboard
Overview
When embedding analytics into your app, you'll often need to display information in industry-specific ways. For example:
- Trade analytics: A specialized map to visualize imports and exports between countries.
- Financial apps: A table with precise sorting and filtering options.
- HR tools: A distribution chart to show candidate demographics.
The sheer variety of visualizations means no single charting library can cover every need. Most BI tools lock you into one or two libraries, offering only limited customization.
This creates a tough choice:
- Settle for generic charts, leading to a subpar user experience.
- Build everything in-house, investing time and resources in analytics infrastructure instead of your core product.
As your analytics needs evolve, rigid BI tools make it increasingly difficult to adapt. That’s why flexibility is crucial when choosing an embedded analytics solution.
At Semaphor, we’ve designed a pluggable architecture that lets you bring your own charting library—or even fully custom components. This gives you complete control over the user experience, enabling you to integrate interactive, custom visuals with just a few lines of code.
Let's take a look at how it works.
Step 1: Create your custom component
The repository below includes a basic example of how to create a custom component for Semaphor.
This starts a local server at http://localhost:5173
. You can open up this repository in your favorite code editor and start exploring the code.
In semaphor-components
folder, you'll find the custom component that we'll add to the Semaphor dashboard. It's a simple component showing recent sales — about 50 lines of code. It takes a data
prop, which is the data to be displayed. But you can make your components as sophisticated as you want.
Once you are satisfied with your custom component, you need to export it as a named export in the index.ts
file. You can export as many components as you want.
And lastly, you will need to specify how this component should appear in Semaphor console with components.config.ts
file.
Step 2: Publish your component to Semaphor
To publish your component to Semaphor, you will first need to install semaphor-cli
. You can do it with the following command:
Now let's initialize a new Semaphor Plugin
for your custom component.
You will be prompted to enter your Semaphor project ID and secret. You can get them from your Semaphor project page.
NOTE: Make sure to initialize the Plugin
and NOT the App.
Once the cli is initalized, you can build and publish your plugin to Semaphor with the following commands.
Step 3: Use your custom component in Semaphor Dashboard
You can now use your custom component in Semaphor dashboard just like any other visual from the visual selector and make it interactive with the rest of the dashboard.
Here is the sample dashboard with the custom component added. If you have any questions feel free to get in touch with us at support@semaphor.cloud