I want to render visualizations in my plugin using embeddables. Here is my code,
I am stuck in the errors and unable to solve this. :
Uncaught TypeError: Cannot read properties of undefined (reading 'create')
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'create')
import { Embeddable, IContainer, EmbeddableInput, EmbeddableOutput } from '@kbn/embeddable-plugin/public';
import { VisualizeEmbeddableFactory } from '../../../src/plugins/visualizations/public/embeddable';
import { VisualizeInput } from '../../../src/plugins/visualizations/public/index';
export const HELLO_WORLD_EMBEDDABLE = 'HELLO_WORLD_EMBEDDABLE';
export class HelloWorldEmbeddable extends Embeddable {
public readonly type = HELLO_WORLD_EMBEDDABLE;
constructor(initialInput: any, parent:any, private visualizeEmbeddableFactory: VisualizeEmbeddableFactory) {
super(initialInput, {}, parent);
}
public render(node: HTMLElement) {
// Use the VisualizeEmbeddableFactory to create and render a visualization
const input: VisualizeInput = {
savedObjectId: '9c2e5a70-5e67-11ee-a009-8b8a031f2175',
// You can provide additional input properties as needed
};
const embeddable = this.visualizeEmbeddableFactory.create(input);
embeddable.render(node);
}
public reload() {
// Implement reload behavior if needed
}
}
And below method neither working nor giving any error:
import { Embeddable, EmbeddableInput, IContainer } from '@kbn/embeddable-plugin/public';
export const HELLO_WORLD_EMBEDDABLE = 'HELLO_WORLD_EMBEDDABLE';
export class HelloWorldEmbeddable extends Embeddable {
// The type of this embeddable. This will be used to find the appropriate factory
// to instantiate this kind of embeddable.
public readonly type = HELLO_WORLD_EMBEDDABLE;
constructor(initialInput: EmbeddableInput, parent?: IContainer) {
super(
initialInput,
{},
parent
);
}
/**
* Render yourself at the dom node using whatever framework you like, angular, react, or just plain
* vanilla js.
* @param node
*/
public render(node: HTMLElement) {
node.innerHTML =
'<div data-embeddable-type="visualization" data-embeddable-id="9c2e5a70-5e67-11ee-a009-8b8a031f2175">h</div>';
}
public reload() {}
}
And I found another solution too with iframe but that is also not working. It is giving error related to permissions like " You do not have permission to access the requested page inside iframe.
import { Embeddable, EmbeddableInput, IContainer } from '@kbn/embeddable-plugin/public';
export const HELLO_WORLD_EMBEDDABLE = 'HELLO_WORLD_EMBEDDABLE';
export class HelloWorldEmbeddable extends Embeddable {
// The type of this embeddable. This will be used to find the appropriate factory
// to instantiate this kind of embeddable.
public readonly type = HELLO_WORLD_EMBEDDABLE;
constructor(initialInput: EmbeddableInput, parent?: IContainer) {
super(
// Input state is irrelevant to this embeddable, just pass it along.
initialInput,
// Initial output state - this embeddable does not do anything with output, so just
// pass along an empty object.
{},
// Optional parent component, this embeddable can optionally be rendered inside a container.
parent
);
}
/**
* Render yourself at the dom node using whatever framework you like, angular, react, or just plain
* vanilla js.
* @param node
*/
public render(node: HTMLElement) {
node.innerHTML =
'<iframe src="/app/visualize#/edit/9c2e5a70-5e67-11ee-a009-8b8a031f2175?_g" height="600" width="800"></iframe>';
}
/**
* This is mostly relevant for time based embeddables which need to update data
* even if EmbeddableInput has not changed at all.
*/
public reload() {}
}