Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playground embed code and sample app flusk code are different. #123547

Closed
fuad47 opened this issue Jun 27, 2024 · 2 comments
Closed

playground embed code and sample app flusk code are different. #123547

fuad47 opened this issue Jun 27, 2024 · 2 comments

Comments

@fuad47
Copy link

fuad47 commented Jun 27, 2024

I can't copy/paste playground code (see screenshot) to sample flusk/python index.js project file because it wont work for some reasons. I tried to modify sample app code to my needs, I am trying to make some design/theme changes to the dashboard, got the code piece from the sandbox and pasted into to the function. but i get error: report.applyTheme({themeJson: theme}); in this line saying that report is not defined. I am not proficient in js. So I need help.

$(function () {
    var reportContainer = $("#report-container").get(0);

    // Initialize iframe for embedding report
    powerbi.bootstrap(reportContainer, { type: "report" });
    
    var models = window["powerbi-client"].models;
    
    var reportLoadConfig = {
        type: "report",
        tokenType: models.TokenType.Embed,

        // Enable this setting to remove gray shoulders from embedded report
        settings: {
            layoutType: models.LayoutType.MobilePortrait
        }
    };

    // You can embed different reports as per your need

    const theme = {
        "name": "Sample Theme",
        "dataColors": ["#990011", "#cc1144", "#ee7799", "#eebbcc", "#cc4477", "#cc5555", "#882222", "#A30E33"],
        "background": "#FFFFFF",
        "foreground": "#007799",
        "tableAccent": "#990011"
    };
    
    // Update the theme by passing in the custom theme.
    // Some theme properties might not be applied if your report has custom colors set.
    try {
        report.applyTheme({themeJson: theme});
        console.log("Custom theme applied, to remove custom theme, reload the report using 'Reload' API.");
    }
    catch (error) {
        console.log(error);
    }

    $.ajax({
        type: "GET",
        url: "/getembedinfo",
        dataType: "json",
        success: function (data) {
            embedData = $.parseJSON(JSON.stringify(data));
            reportLoadConfig.accessToken = embedData.accessToken;
            
            // You can embed different reports as per your need
            reportLoadConfig.embedUrl = embedData.reportConfig[0].embedUrl;

            // Use the token expiry to regenerate Embed token for seamless end user experience
            // Refer https://aka.ms/RefreshEmbedToken
            tokenExpiry = embedData.tokenExpiry;

            // Embed Power BI report when Access token and Embed URL are available
            var report = powerbi.embed(reportContainer, reportLoadConfig);

            // Triggers when a report schema is successfully loaded
            report.on("loaded", function () {
                console.log("Report load successful")
            });

            // Triggers when a report is successfully embedded in UI
            report.on("rendered", function () {
                console.log("Report render successful")
            });
            //---------

            //-----------------
            // Clear any other error handler event
            report.off("error");

            // Below patch of code is for handling errors that occur during embedding
            report.on("error", function (event) {
                var errorMsg = event.detail;

                // Use errorMsg variable to log error in any destination of choice
                console.error(errorMsg);
                return;
            });
        },
        error: function (err) {

            // Show error container
            var errorContainer = $(".error-container");
            $(".embed-container").hide();
            errorContainer.show();

            // Format error message
            var errMessageHtml = "<strong> Error Details: </strong> <br/>" + $.parseJSON(err.responseText)["errorMsg"];
            errMessageHtml = errMessageHtml.split("\n").join("<br/>")

            // Show error message on UI
            errorContainer.html(errMessageHtml);
        }
    });
});

image_2024-06-27_144025238

@PesalaPavan
Copy link
Contributor

@fuad47
It would be great if you could add a link to the documentation you are following for these steps? This would help us redirect the issue to the appropriate team. Thanks!!

@PesalaPavan
Copy link
Contributor

@fuad47
We are going to close this thread but if there are any further questions regarding the documentation, please tag me in your reply and we will be happy to continue the conversation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants