Usare bootstrap per migliorare le prestazioni

powerbi.bootstrap è un metodo introdotto in Client SDK versione 2.9.0 per aiutare gli sviluppatori ad incorporare entità di Power BI più velocemente e ottenere prestazioni migliori.

L'incorporamento di un report usando powerbi.embed richiede più parametri, ad esempio reportId, embedURLe accessToken. Questi parametri non sono sempre disponibili immediatamente.

powerbi.bootstrap consente di iniziare a incorporare prima che siano disponibili tutti i parametri necessari. L'API di bootstrap prepara e inizializza l'iFrame.

Dopo aver ricevuto i parametri necessari, powerbi.embed(element, config) deve essere chiamato sullo stesso elemento HTML.

Bootstrap API

Il powerbi.bootstrap(element, config) metodo riceve un elemento e una configurazione, uguale a powerbi.embed(...).

/**
    * Given an HTML element and entityType, creates a new component instance, and bootstrap the iframe for embedding.
    *
    * @param {HTMLElement} an HTML Element where you need to embed. must be the same div element you will use in powerbi.embed.
    * @param {IBootstrapEmbedConfiguration} config: a bootstrap config.
    */
bootstrap(element: HTMLElement, config: IBootstrapEmbedConfiguration): embed.Embed;

Configurazione di incorporamento bootstrap

interface IBootstrapEmbedConfiguration {
  type: string;
  hostname?: string;
  embedUrl?: string;
  settings?: ISettings;
}

Parametri di configurazione:

  • type (obbligatorio): tipo di entità da incorporare, ad esempio 'report', 'dashboard', 'tile', 'qna' o 'visual'.
  • hostname: se non si ha ancora un embedURL nome host, è possibile specificare un nome host. Il nome host è il nome di dominio dell'URL di incorporamento. Ad esempio, se l'URL di incorporamento è 'https://app.powerbi.com/reportEmbed' il nome host è 'https://app.powerbi.com/'. Se non viene fornito alcun nome host o embedUrl, viene usato il nome host predefinito, https://app.powerbi.com/, .
  • embedUrl: lo stesso URL di incorporamento che verrà fornito in un secondo momento a powerbi.embed. Se non viene fornito alcun nome host o embedUrl, viene usato il nome host predefinito, https://app.powerbi.com/, .
  • impostazioni: per incorporare il report in un layout per dispositivi mobili o per fornire impostazioni locali (lingua), includere questi parametri nelle impostazioni iniziali.

Esempi di Bootstrap

Gli esempi seguenti forniscono un riferimento per il metodo bootstrap durante l'incorporamento di entità di Power BI.

Nota

Assicurarsi di chiamare powerbi.embed dopo aver ricevuto i parametri di incorporamento.

Per eseguire il bootstrap per l'incorporamento di un report:

powerbi.bootstrap(
        reportContainerDivElement,
        {
            type: 'report',
        }
    );

Per eseguire il bootstrap per l'incorporamento di un dashboard:

powerbi.bootstrap(
        reportContainerDivElement,
        {
            type: 'dashboard',
            embedUrl: "https://app.powerbi.com/dashboardEmbed?dashboardId=06e3ba63-47ea-4579-b010-fdb5484b325a&config=eyJjbHVzdGVyVXJsIjoiaHR0cHM6mLndpbmRvd3MubmV0In0="
        }
    );

Per eseguire il bootstrap per incorporare un report solo con il nome host:

powerbi.bootstrap(
        reportContainerDivElement,
        {
            type: 'report',
            hostname: "https://app.powerbi.com"
        }
    );

Per eseguire il bootstrap per incorporare un report con layout per dispositivi mobili:

powerbi.bootstrap(
        reportContainerDivElement,
        {
            type: 'report',
            hostname: "https://app.powerbi.com",
            settings: {
	            layoutType: models.LayoutType.MobilePortrait
            }
        }
    );

Limitazioni

  • Non è possibile modificare le entità di avvio seguenti senza chiamare powerbi.reset(element).

    • Tipo di componente (report, dashboard): ad esempio, se si avvia un report, è possibile incorporare solo i report nello stesso elemento HTML.
    • Layout (desktop/mobile)
    • Impostazioni locali (lingua)
  • Il powerbi.bootstrap metodo non è supportato durante l'incorporamento di report impaginati.

Passaggi successivi