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

Superset 4.0.2 : Dashboard Reports Appearance via Email #29775

Open
oyku-buyukakin opened this issue Jul 30, 2024 · 3 comments
Open

Superset 4.0.2 : Dashboard Reports Appearance via Email #29775

oyku-buyukakin opened this issue Jul 30, 2024 · 3 comments
Labels
dashboard:export Related to exporting dashboards

Comments

@oyku-buyukakin
Copy link

Description

Hello, I recently started using Superset 4.0.2. I have a few problems with it. For example;

  1. When I share a dashboard via email with other people, they only can see first five or six plots in email, but I want all my plot to be seen at my email.
  2. I can't control width and height of cell in Table chart.
  3. If I want to select two of my plots in dashboard and want to share it via email, I can't do that. I only can share one plot as PNG format.
  4. Most importantly, I have a dashboard contains ten table chart and I want to share all my charts as text via email. As I can see Superset has no sharing option for dashboards as text format.

I would be very glad if you could help me with these issues.

@dosubot dosubot bot added the dashboard:export Related to exporting dashboards label Jul 30, 2024
Copy link

dosubot bot commented Jul 30, 2024

To address your issues with Superset 4.0.2:

  1. Including All Plots in Email:
    To ensure all plots from a dashboard are included in the email, you need to modify the email template to iterate over all the charts in the dashboard and include them in the email content. Here is a sample code snippet to achieve this:

    from superset import db
    from superset.models.dashboard import Dashboard
    
    def get_dashboard_charts(dashboard_slug):
        dashboard = db.session.query(Dashboard).filter_by(slug=dashboard_slug).first()
        if not dashboard:
            return []
    
        charts = []
        for component in dashboard.position_json['CHARTS']:
            chart_id = component['meta']['chartId']
            chart_name = component['meta']['sliceName']
            charts.append((chart_id, chart_name))
        
        return charts
    
    def generate_email_content(dashboard_slug):
        charts = get_dashboard_charts(dashboard_slug)
        email_content = "<h1>Dashboard Charts</h1>"
        for chart_id, chart_name in charts:
            email_content += f"<h2>{chart_name}</h2>"
            email_content += f'<img src="http://your-superset-url/superset/slice/{chart_id}/thumbnail" alt="{chart_name}"/>'
        
        return email_content
    
    # Example usage
    dashboard_slug = "tabbed_dash"
    email_content = generate_email_content(dashboard_slug)
    print(email_content)

    Replace "http://your-superset-url" with your actual Superset URL. This will generate an email content with all the charts from the specified dashboard [1].

  2. Controlling Width and Height of Table Chart Cells:
    You can adjust the chart dimensions directly in the dashboard's JSON configuration. Here is an example:

    {
        "CHART-06Kg-rUggO": {
            "children": [],
            "id": "CHART-06Kg-rUggO",
            "meta": {
                "chartId": 617,
                "height": 42,  // Adjust the height here
                "sliceName": "Number of Girls",
                "width": 4     // Adjust the width here
            },
            "parents": [
                "ROOT_ID",
                "TABS-lV0r00f4H1",
                "TAB-NF3dlrWGS",
                "ROW-kHj58UJg5N",
                "COLUMN-_o23occSTg",
                "TABS-CslNeIC6x8",
                "TAB-SDz1jDqYZ2",
                "ROW-DnYkJgKQE"
            ],
            "type": "CHART"
        },
        // Other chart configurations...
    }

    Adjust the height and width values as needed [1].

  3. Sharing Selected Plots via Email:
    Currently, Superset does not support sharing multiple selected plots as a single email attachment directly. You might need to manually create a custom email template that includes the selected plots.

  4. Sharing Dashboards as Text via Email:
    Superset allows for text-based sharing through the context_markdown field in report schedules. You can use this field to include text-based content in your email reports. Here is an example:

    show_columns = [
        "id",
        "active",
        "chart.id",
        "chart.slice_name",
        "chart.viz_type",
        "context_markdown",
        "creation_method",
        "crontab",
        "custom_width",
        "dashboard.dashboard_title",
        "dashboard.id",
        "database.database_name",
        "database.id",
        "description",
        "extra",
        "force_screenshot",
        "grace_period",
        "last_eval_dttm",
        "last_state",
        "last_value",
        "last_value_row_json",
        "log_retention",
        "name",
        "owners.first_name",
        "owners.id",
        "owners.last_name",
        "recipients.id",
        "recipients.recipient_config_json",
        "recipients.type",
        "report_format",
        "sql",
        "timezone",
        "type",
        "validator_config_json",
        "validator_type",
        "working_timeout",
        "email_subject",
    ]

    The context_markdown field allows for text-based sharing within the report schedules [2].

These solutions should help you address the issues you're facing with Superset 4.0.2.

To continue talking to Dosu, mention @dosu.

@oyku-buyukakin
Copy link
Author

@dosu All the solutions you suggested to me include configurations made via Python, but I need to do this on Superset. Could you help me?

@oyku-buyukakin oyku-buyukakin reopened this Aug 6, 2024
Copy link

dosubot bot commented Aug 6, 2024

  1. Including All Plots in Email:
    To include all plots from a dashboard in an email, you need to modify the shareByEmail function to ensure it captures all the plots. Here's an example of how you might do this:

    const shareByEmail = useCallback(async () => {
      try {
        const subject = t('Superset Dashboard');
        const chartPermalinks = await Promise.all(
          dashboards.map(async (dashboard) => {
            const url = await getChartPermalink(dashboard.latestQueryFormData);
            return `${dashboard.slice_name}: ${url}`;
          })
        );
        const body = encodeURIComponent(t('Check out these charts:\n\n%s', chartPermalinks.join('\n')));
        window.location.href = `mailto:?Subject=${subject}&Body=${body}`;
      } catch (error) {
        addDangerToast(t('Sorry, something went wrong. Try again later.'));
      }
    }, [addDangerToast, dashboards]);
  2. Controlling Width and Height of Table Chart Cells:
    You can customize the width of columns in Table charts using the columnWidth property and the column_config control. However, there is no direct mention of customizing the height of individual cells, but the overall table height can be managed using the height property.

    {config.columnWidth ? (
      <div
        style={{
          width: columnWidth,
          height: 0.01,
        }}
      />
    ) : null}
    {
      name: 'column_config',
      config: {
        type: 'ColumnConfigControl',
        label: t('Customize columns'),
        description: t('Further customize how to display each column'),
        width: 400,
        height: 320,
        renderTrigger: true,
        shouldMapStateToProps() {
          return true;
        },
        mapStateToProps(explore, _, chart) {
          return {
            queryResponse: chart?.queriesResponse?.[0] as
              | ChartDataResponseResult
              | undefined,
          };
        },
      },
    }
  3. Sharing Selected Plots via Email:
    Superset currently does not support sharing multiple selected plots as a single email attachment directly. You might need to manually create a custom email template that includes the selected plots.

  4. Sharing Dashboards as Text via Email:
    Superset allows for text-based sharing through the context_markdown field in report schedules. You can use this field to include text-based content in your email reports. Here is an example:

    @pytest.fixture()
    def create_report_email_chart_with_text():
        chart = db.session.query(Slice).first()
        chart.query_context = '{"mock": "query_context"}'
        report_schedule = create_report_notification(
            email_target="target@email.com",
            chart=chart,
            report_format=ReportDataFormat.TEXT,
        )
        yield report_schedule
        cleanup_report_schedule(report_schedule)

These solutions should help you address the issues you're facing with Superset 4.0.2.

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:export Related to exporting dashboards
Projects
None yet
Development

No branches or pull requests

1 participant