GitHub user dosubot[bot] added a comment to the discussion: How to create a 
custom map using Viz plugin

<!-- Answer -->
Here's how Superset registers custom visualization plugins on the backend and 
frontend:

**Backend:**  
Superset discovers visualization types by scanning all subclasses of `BaseViz` 
in `superset/viz.py` at import time. To register your custom viz, you must 
define your class as a subclass of `BaseViz` with a unique `viz_type` string, 
and—crucially—ensure the class is either defined directly in `superset/viz.py` 
or imported into it. If your class is in a separate file, you must add an 
import statement for it in `superset/viz.py` so it gets picked up when the 
`viz_types` registry is built. There is no explicit registration call; the 
import is what makes it discoverable. This is why `MapboxViz` works: it's 
defined in `superset/viz.py` and thus auto-discovered by the registry logic at 
the bottom of that file 
([source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/viz.py#L104-L2405)).

**Frontend:**  
You must import your plugin in 
`superset-frontend/src/visualizations/presets/MainPreset.js` and add it to the 
`plugins` array with a key that matches your backend `viz_type` string (e.g., 
`'custom_map'`). The frontend looks up plugins by this key, so if it doesn't 
match, or isn't registered, your chart won't render 
([source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/src/visualizations/presets/MainPreset.js#L19-L191)).

**Troubleshooting checklist:**  
- Make sure your custom viz class is imported or defined in `superset/viz.py` 
before the `viz_types` registry is built.
- Confirm the frontend plugin key matches the backend `viz_type`.
- Rebuild your Docker image and restart Superset after code changes.
- If using Docker volumes, check that your changes are reflected in the running 
container.
- Double-check that the chart you're querying exists in the database.

If you follow these steps, your custom viz should be registered and 
discoverable by both backend and frontend. If you still get a 404 or "not 
found," it's almost always due to a missing import or a key mismatch.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/7a45b493-2bb0-4dcb-bccc-e4d998d5ab39?feedback_type=other)</sup>

[![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Here%27s%20how%20Superset%20registers%20custom%20visualization%20plugins%20on%20the%20backend%20and%20frontend%3A%0A%0A%2A%2ABackend%3A%2A%2A%20%20%0ASuperset%20discovers%20visualization%20types%20by%20scanning%20all%20subclasses%20of%20%60BaseViz%60%20in%20%60superset/viz.py%60%20at%20import%20time.%20To%20register%20your%20custom%20viz%2C%20you%20must%20define%20your%20class%20as%20a%20subclass%20of%20%60BaseViz%60%20with%20a%20unique%20%60viz_type%60%20string%2C%20and%E2%80%94crucially%E2%80%94ensure%20the%20class%20is%20either%20defined%20directly%20in%20%60superset/viz.py%60%20or%20imported%20into%20it.%20If%20your%20class%20is%20in%20a%20separate%20file%2C%20you%20must%20add%20an%20import%20statement%20for%20it%20in%20%60superset/viz.py%60%20so%
 
20it%20gets%20picked%20up%20when%20the%20%60viz_types%60%20registry%20is%20built.%20There%20is%20no%20explicit%20registration%20call%3B%20the%20import%20is%20what%20makes%20it%20discoverable.%20This%20is%20why%20%60MapboxViz%60%20works%3A%20it%27s%20defined%20in%20%60superset/viz.py%60%20and%20thus%20auto-discovered%20by%20the%20registry%20logic%20at%20the%20bottom%20of%20that%20file%20%28%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/viz.py%23L104-L2405%29%29.%0A%0A%2A%2AFrontend%3A%2A%2A%20%20%0AYou%20must%20import%20your%20plugin%20in%20%60superset-frontend/src/visualizations/presets/MainPreset.js%60%20and%20add%20it%20to%20the%20%60plugins%60%20array%20with%20a%20key%20that%20matches%20your%20backend%20%60viz_type%60%20string%20%28e.g.%2C%20%60%27custom_map%27%60%29.%20The%20frontend%20looks%20up%20plugins%20by%20this%20key%2C%20so%20if%20it%20doesn%27t%20match%2C%20or%20isn%27t%20registered%2C%20your%20chart%20won%27t%
 
20render%20%28%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/src/visualizations/presets/MainPreset.js%23L19-L191%29%29.%0A%0A%2A%2ATroubleshooting%20checklist%3A%2A%2A%20%20%0A-%20Make%20sure%20your%20custom%20viz%20class%20is%20imported%20or%20defined%20in%20%60superset/viz.py%60%20before%20the%20%60viz_types%60%20registry%20is%20built.%0A-%20Confirm%20the%20frontend%20plugin%20key%20matches%20the%20backend%20%60viz_type%60.%0A-%20Rebuild%20your%20Docker%20image%20and%20restart%20Superset%20after%20code%20changes.%0A-%20If%20using%20Docker%20volumes%2C%20check%20that%20your%20changes%20are%20reflected%20in%20the%20running%20container.%0A-%20Double-check%20that%20the%20chart%20you%27re%20querying%20exists%20in%20the%20database.%0A%0AIf%20you%20follow%20these%20steps%2C%20your%20custom%20viz%20should%20be%20registered%20and%20discoverable%20by%20both%20backend%20and%20frontend.%20If%20you%20still%20get%20a%20404%20o
 
r%20%22not%20found%2C%22%20it%27s%20almost%20always%20due%20to%20a%20missing%20import%20or%20a%20key%20mismatch.)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/36591)

GitHub link: 
https://github.com/apache/superset/discussions/36591#discussioncomment-15267361

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to