Open oyku-buyukakin opened 3 months ago
To address your issues with Superset 4.0.2:
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].
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].
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.
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.
@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?
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]);
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,
};
},
},
}
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.
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.
Description
Hello, I recently started using Superset 4.0.2. I have a few problems with it. For example;
I would be very glad if you could help me with these issues.