superset icon indicating copy to clipboard operation
superset copied to clipboard

export to .CSV in embedding superset not working

Open baguskna opened this issue 2 years ago • 9 comments

Hi, I have successfully embedded the dashboard and we want feature export to .CSV , but it is not working it said

Blocked opening 'URL' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.
Blocked form submission to 'URL' because the form's frame is sandboxed and the 'allow-forms' permission is not set.

I was able to override the iframe with this way

    const embed = await embedDashboard({
      id: dashboardId,
      supersetDomain: URL,
      mountPoint: document.querySelector("#superset-id"),
      fetchGuestToken: () => guestToken,
      dashboardUiConfig: {
        hideTitle: true,
        hideChartControls: false,
        hideTab: true,
      },
    });

    const size = await embed.getScrollSize();

    if (size.width !== 0) {
      const iframe = document.querySelector("iframe") as HTMLIFrameElement;
      iframe.setAttribute(
        "sandbox",
        "allow-same-origin allow-scripts allow-presentation allow-downloads allow-forms allow-popups allow-popups-to-escape-sandbox"
      );
    }
    

still it returns the same error as I mentioned above, by any chance is there a way we can fix this?

baguskna avatar Oct 17 '22 09:10 baguskna

I am getting the same error. I have tried few options but seems like you can't change the frame attributes

fordsworth avatar Oct 22 '22 06:10 fordsworth

I am getting the same error too.. Would be great if this bug could be fixed, in case I find a workaround I'll post it here

blue-lm avatar Oct 31 '22 08:10 blue-lm

Looks like the issue is in the SuperSetClient.ts file? A hiddenform is created in the code below, I guess we need to add the attributes that were suggested by @baguskna to this hiddenform? Not sure how to do this though:

async postForm(url: string, payload: Record<string, any>, target = '_blank') {
    if (url) {
      await this.ensureAuth();
      const hiddenForm = document.createElement('form');
      hiddenForm.action = url;
      hiddenForm.method = 'POST';
      hiddenForm.target = target;

blue-lm avatar Nov 01 '22 08:11 blue-lm

Hello @blue-lm if you put _self instead of _blank .csv is downloading in the same page and dissapiar allow-popups error, but I still have allow-forms error althought I add it to iframe. I don't understand because in sdk allow-forms is added but after It don't apper and I have to add it...

MMendozaEscalona avatar Nov 17 '22 08:11 MMendozaEscalona

Still not working, we ended up using post message to transfer the .CSV, it is working now

baguskna avatar Nov 17 '22 09:11 baguskna

Still not working, we ended up using post message to transfer the .CSV, it is working now

can you please post the code block

prnth22 avatar Nov 17 '22 09:11 prnth22

A fix for this would probably be to provide a config for attributes to pass to the iframe.

nytai avatar Nov 20 '22 07:11 nytai

Has anyone found a workaround for this issue yet? If so, would it be possible to share the specific code / javascript I can add to the html page that contains the embedded superset frame? I think the challenge is that the CSV export iframe is created after clicking on the export to CSV button, so it's difficult to assign different attributes to the iframe. This bug is preventing us from using the superset embedded iframe in production as users are not able to export CSV files (which is considered essential functionality).

blue-lm avatar Nov 28 '22 14:11 blue-lm

I am faced with the same problem. I want to download CSV and open a new window from a tag in the table chart.

oyasuyuki avatar Nov 29 '22 03:11 oyasuyuki

I found the solution(but I don't know if this solution is correct) The solution is to use @preset-sdk/embedded instead of @superset-ui/embedded-sdk. I can download csv and open the new window.

@superset-ui/embedded-sdk is old and not updated. superset-embedded-sdk in the superset repository is updated, but not reflected in the npm package.

oyasuyuki avatar Dec 01 '22 08:12 oyasuyuki

I found the solution(but I don't know if this solution is correct) The solution is to use @preset-sdk/embedded instead of @superset-ui/embedded-sdk. I can download csv and open the new window.

@superset-ui/embedded-sdk is old and not updated. superset-embedded-sdk in the superset repository is updated, but not reflected in the npm package.

Thank you!! This resolved the issue for me

blue-lm avatar Dec 16 '22 16:12 blue-lm

Unfortunately I just encountered a new issue with this functionality - in the embedded dashboard the export CSV button appears to ignore filtering, or apply it incorrectly. So the table itself shows filtered data as expected, but the export CSV button shows unfiltered data, or at least the filtering appears to be applied incorrectly. I'm using the {{ current_username(add_to_cache_keys=False) }} value as part of filtering. The non-embedded dashboard works correctly. Does anyone know how I make the export CSV filtering work correctly in the embedded dashboard?

Edit: On second thought it appears to perhaps be a caching issue, as filtering is being applied but on the incorrect customer (sometimes). Any suggestions on how I can avoid the embedded superset csv export to use a previous (cached) customer name, instead of the current one?

blue-lm avatar Jan 10 '23 08:01 blue-lm

Related thread on Slack here: https://apache-superset.slack.com/archives/C01EP56QGTS/p1668673732265359

I'm going to close this issue as resolved, since it sounds like the original issue indeed was resolved. If anyone objects to this, we can most certainly revisit. @blue-lm I think it might be worth opening a new issue describing what you're facing (and steps to replicate it) so that we can handle that in a new thread.

Thanks!

rusackas avatar Jan 31 '23 18:01 rusackas

hi, can anyone help me with this problem ? I have tried to use both @preset-sdk/embedded and @superset-ui/embedded-sdk libs but I still can not see any export function in my embedded dashboard. Much appreciate if anyone have any solution 🙏 Screenshot 2023-02-07 at 10 40 49

duonghuyom avatar Feb 07 '23 03:02 duonghuyom

hi, can anyone help me with this problem ? I have tried to use both @preset-sdk/embedded and @superset-ui/embedded-sdk libs but I still can not see any export function in my embedded dashboard. Much appreciate if anyone have any solution 🙏 Screenshot 2023-02-07 at 10 40 49

It should be the role setting inside your superset, allow them to be Downloadable

baguskna avatar Feb 09 '23 07:02 baguskna

hi, can anyone help me with this problem ? I have tried to use both @preset-sdk/embedded and @superset-ui/embedded-sdk libs but I still can not see any export function in my embedded dashboard. Much appreciate if anyone have any solution 🙏 Screenshot 2023-02-07 at 10 40 49

It should be the role setting inside your superset, allow them to be Downloadable

can you show me where to set that ? i have set the permission 'can csv on Superset' but in my embedded dashboard, it still not display the 'Export CSV' option.

duonghuyom avatar Feb 09 '23 07:02 duonghuyom

hi, can anyone help me with this problem ? I have tried to use both @preset-sdk/embedded and @superset-ui/embedded-sdk libs but I still can not see any export function in my embedded dashboard. Much appreciate if anyone have any solution 🙏 Screenshot 2023-02-07 at 10 40 49

It should be the role setting inside your superset, allow them to be Downloadable

can you show me where to set that ? i have set the permission 'can csv on Superset' but in my embedded dashboard, it still not display the 'Export CSV' option.

Can you check, are you inserting the right role? Mine has these set up in embedded role, not sure if it helps Screen Shot 2023-02-09 at 14 53 29

baguskna avatar Feb 09 '23 07:02 baguskna

hi, can anyone help me with this problem ? I have tried to use both @preset-sdk/embedded and @superset-ui/embedded-sdk libs but I still can not see any export function in my embedded dashboard. Much appreciate if anyone have any solution 🙏 Screenshot 2023-02-07 at 10 40 49

It should be the role setting inside your superset, allow them to be Downloadable

can you show me where to set that ? i have set the permission 'can csv on Superset' but in my embedded dashboard, it still not display the 'Export CSV' option.

Can you check, are you inserting the right role? Mine has these set up in embedded role, not sure if it helps Screen Shot 2023-02-09 at 14 53 29

i have added all the permission relate to csv but it still not display export csv option in my embedded dashboard, do i have to config anything else ? I also added Admin permission but it still not have the button

duonghuyom avatar Feb 09 '23 08:02 duonghuyom

Hi @duonghuyom , just to be sure: do you have Superset v2.0.0 or higher installed? I believe the CSV export functionality wasn't available in older versions.

blue-lm avatar Mar 15 '23 12:03 blue-lm

Hi @duonghuyom , just to be sure: do you have Superset v2.0.0 or higher installed? I believe the CSV export functionality wasn't available in older versions.

I have updated the superset version and now it have the export csv function. Thank you

duonghuyom avatar Mar 16 '23 02:03 duonghuyom

@duonghuyom, which version are you running right now?

I don't see on my version CleanShot 2023-08-17 at 14 24 44@2x CleanShot 2023-08-17 at 14 25 14@2x

mikkhait avatar Aug 17 '23 21:08 mikkhait

hi @mikkhait, i used version 1.5.3

duonghuyom avatar Aug 18 '23 10:08 duonghuyom

I still have the same problem with 3.0.1 even with the following set of permissions CleanShot 2023-10-31 at 13 52 34@2x my tables do not get the csv export feature for the embedded dashboard. Non-embedded working fine

CleanShot 2023-10-31 at 13 52 57@2x

mikkhait avatar Oct 31 '23 20:10 mikkhait

Same here, using version 4.0.1, table can be exported to csv from superset instance but export menu does not appear, as shown in @mikkhait image.

After further efforts, we discovered that the user in the embedded chart is no the one who authenticates for the token emission. Everything worked fine once given appropriate permissions to the GUEST role.

ikerd avatar May 21 '24 14:05 ikerd

@ikerd have you set the feature flag ALLOW_FULL_CSV_EXPORT ? I'm using 4.0.1 and no exports options and I want to use "View as Table" and "Drill to Detail" but it show only "Force Refresh" and "Enter full screen".

HeribertoAlves avatar May 23 '24 14:05 HeribertoAlves

@ikerd have you set the feature flag ALLOW_FULL_CSV_EXPORT ? I'm using 4.0.1 and no exports options and I want to use "View as Table" and "Drill to Detail" but it show only "Force Refresh" and "Enter full screen".

@HeribertoAlves as far as I know ALLOW_FULL_CSV_EXPORT is a feature flag used to bypass table pagination on export, it allows using the "Export to Full CSV" or "Export to Full EXCEL" buttons. It does not have anything to do with the fact of the Download menu not appearing.

In our case it has been solved correctly setting the permissions for the GUEST role and not the one of the user used to get the authentication token.

ikerd avatar May 23 '24 14:05 ikerd

@ikerd have you set the feature flag ALLOW_FULL_CSV_EXPORT ? I'm using 4.0.1 and no exports options and I want to use "View as Table" and "Drill to Detail" but it show only "Force Refresh" and "Enter full screen".

@HeribertoAlves as far as I know ALLOW_FULL_CSV_EXPORT is a feature flag used to bypass table pagination on export, it allows using the "Export to Full CSV" or "Export to Full EXCEL" buttons. It does not have anything to do with the fact of the Download menu not appearing.

In our case it has been solved correctly setting the permissions for the GUEST role and not the one of the user used to get the authentication token.

Thanks for your reply @ikerd !

I set GUEST_ROLE_NAME = "DashboardEmbedded". And then set DashboardEmbedded with all the permission mentioned above. But so far is not working.

I just forgot to set "can csv on Superset" and now is working.

I Wonder now how can enable(if possible) "Drill to detail"

HeribertoAlves avatar May 23 '24 17:05 HeribertoAlves