You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "srijani-smsrc (via GitHub)" <gi...@apache.org> on 2026/05/12 04:14:53 UTC
[D] render as html format [superset]
GitHub user srijani-smsrc created a discussion: render as html format
i have used concated span in custom sql metrics to give desired colours , but when i am downloading as excel it is downloading the entire span code as well , when i only want the values
@dosu
GitHub link: https://github.com/apache/superset/discussions/40044
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] render as html format [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: render as html format
<!-- Answer -->
Unfortunately, maintaining a separate "clean" metric alongside an HTML metric in a Pivot Table isn't practical — you'd end up with both metrics displayed as separate columns/rows in the pivot, and there's no built-in way to selectively hide one during export while showing the other on screen.
**Better approach: Use Pivot Table's native Conditional Formatting instead.**
The Pivot Table V2 has built-in conditional formatting support [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx) that applies cell background colors based on metric values — no HTML needed. To use it:
1. Replace your HTML-wrapped custom SQL metric with a plain metric (just the raw value, no `<span>` tags)
2. In the chart's **Customize** tab, look for the **Conditional Formatting** section
3. Add color rules based on value thresholds (e.g., red if value < X, green if value > Y)
This approach keeps your data clean, so exports will contain only the numeric/text values without any HTML markup.
**Caveat:** The Pivot Table's conditional formatting is more limited than the regular Table chart — it supports threshold-based background colors but lacks some options like "green for increase, red for decrease" [[2]](https://github.com/apache/superset/pull/37362). If your coloring logic is more complex than simple thresholds, this may not fully cover your use case.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=9f2ad85a-49d6-4635-8756-a08d89a5f0f7) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/40044#discussioncomment-16887535
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] render as html format [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: render as html format
<!-- Answer -->
The best single file to modify is **`superset/common/query_context_processor.py`** — specifically the `get_data()` method [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/common/query_context_processor.py#L734-L754). This is the central point where all chart data (Table, Pivot Table, etc.) passes through before being converted to CSV or Excel. Modifying it here covers both export formats for all chart types.
**Where to add the logic:**
In the `get_data()` method, add HTML stripping **after** the verbose column mapping and **before** the format conversion (CSV/XLSX). Around line 744, before the CSV/Excel conversion begins:
```python
# After verbose_map processing, add HTML stripping:
for col in df.columns:
if df[col].dtype == "object":
df[col] = df[col].apply(
lambda x: re.sub(r'<[^>]+>', '', x) if isinstance(x, str) else x
)
```
You'll need to `import re` at the top of the file.
**Supporting files for reference:**
- `superset/utils/csv.py` — CSV export utility [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/csv.py)
- `superset/utils/excel.py` — Excel export utility [[3]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/excel.py)
**Tip:** You may want to make this conditional (e.g., behind a feature flag or config option like `STRIP_HTML_ON_EXPORT = True` in `config.py`) so it doesn't unexpectedly alter exports for users who intentionally want HTML in their exported data.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=b218e750-e69d-4e8a-9bdd-7495edef1d13) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/40044#discussioncomment-16887674
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] render as html format [superset]
Posted by "srijani-smsrc (via GitHub)" <gi...@apache.org>.
GitHub user srijani-smsrc added a comment to the discussion: render as html format
Use a separate metric for export — Create a version of your metric without the HTML wrapping (just the raw values) and use that when you need to export.
@dosu how to do this in pivot table
GitHub link: https://github.com/apache/superset/discussions/40044#discussioncomment-16887524
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] render as html format [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: render as html format
<!-- Answer -->
This is expected behavior in Superset — the "Render as HTML" option only controls how values are **displayed** in the browser. When you export to Excel/CSV, Superset pulls the raw database query results directly, so your `<span>` tags come through as-is [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/common/query_context_processor.py) [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx).
**Workarounds:**
1. **Use a separate metric for export** — Create a version of your metric without the HTML wrapping (just the raw values) and use that when you need to export.
2. **Post-process in Excel** — Use Find & Replace or a formula like `=SUBSTITUTE()` to strip the span tags after export.
3. **Use conditional formatting in the Table chart instead** — If your goal is just coloring, consider using Superset's built-in **Conditional Formatting** feature (under the "Customize" tab in the Table chart). This applies color to cells natively without injecting HTML into the metric values, so exports will contain only clean numeric/text values.
Option 3 is the recommended approach if it fits your use case, since it separates styling from data and avoids the export issue entirely.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=46a58b90-a182-489b-b7d7-ac1a6081a952) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/40044#discussioncomment-16887507
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] render as html format [superset]
Posted by "srijani-smsrc (via GitHub)" <gi...@apache.org>.
GitHub user srijani-smsrc added a comment to the discussion: render as html format
Post-process in Excel — Use Find & Replace or a formula like =SUBSTITUTE() to strip the span tags after export. i want to do this for all pivot table and table charts which file should i change
@dosu
GitHub link: https://github.com/apache/superset/discussions/40044#discussioncomment-16887609
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org