marcskovmadsen/holoviz-mcp/panel-custom-components

Claude Code and agent skill by marcskovmadsen/holoviz-mcp

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Build custom Panel components using JSComponent (vanilla JS, web components), ReactComponent (React/JSX), AnyWidgetComponent (AnyWidget spec for cross-platform), or MaterialUIComponent (Material UI themed). Use when wrapping JS libraries, creating interactive widgets, or building themed components. Includes decision guide, best practices, DOs/DON'Ts, and Playwright UI testing patterns.

Install

npx vskill@latest install marcskovmadsen/holoviz-mcp/panel-custom-components

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

Panel Custom Components

This skill covers building custom Panel components that bridge Python and JavaScript. Use it when you need to:

  • Wrap JavaScript libraries (D3, Leaflet, Chart.js, etc.)
  • Create interactive widgets with custom UI behavior
  • Create Material UI themed components for panel-material-ui apps

Prerequisites: Solid JavaScript and React knowledge assumed.

1. Decision Guide - Which Component Type to Use

Comparison Table
CriteriaJSComponentReactComponentAnyWidgetComponentMaterialUIComponent
Best ForVanilla JS libs, Web Components, D3, Leaflet, simple widgetsReact ecosystem, complex state, MUI/Chakra libsCross-platform (Jupyter+Panel), community sharingpanel-material-ui apps, MUI theming
JS PatternDOM manipulationReact/JSXAnyWidget AFM specReact/JSX + MUI
State Syncmodel.on('param', cb)model.useState("param")model.get/set/save_changesmodel.useState("param")
Exportexport function render({model, el})export function render({model, el})export default { render }export function render({model, el})
Base Importpanel.custom.JSComponentpanel.custom.ReactComponentpanel.custom.AnyWidgetComponentpanel_material_ui.MaterialUIComponent
Decision Flow
┌─────────────────────────────────────────────────────────────────┐
│ Need Material UI theming / using panel-material-ui? │
│ YES → MaterialUIComponent │
│ NO ↓ │
├─────────────────────────────────────────────────────────────────┤
│ Need Jupyter compatibility / sharing community widgets? │
│ YES → AnyWidgetComponent │
│ NO ↓ │
├─────────────────────────────────────────────────────────────────┤
│ Using React libraries or need complex state management? │
│ YES → ReactComponent │
│ NO ↓ │
├─────────────────────────────────────────────────────────────────┤
│ Vanilla JS, Web Components, or simple DOM manipulation? │
│ YES → JSComponent │
└─────────────────────────────────────────────────────────────────┘

2. Development Workflow

Important: Build custom components in two phases. By experience, getting JS imports and responsive sizing to work can take significant debugging effort.
Phase 1: POC (Proof of Concept)

Before building the full component, create a minimal example using your actual target library that validates:

  1. JS imports work - The library loads without "Unexpected token 'export'" or CORS errors
  2. Library renders something - You can see actual output from the library (a chart, a map, a widget, etc.)
  3. Python-JS connection works - State syncs bidirectionally via model.on() / model.useState()
  4. Element displays responsively - Component fills container and handles resize events

The goal is to see your library working in a Panel component before investing time in the full implementation. Use the template below as a starting point, but replace the placeholder library with your actual library and render something real from it.

Minimal POC template:

python
import param
from panel.custom import JSComponent
class MyComponentPOC(JSComponent):
"""Minimal POC to validate imports and responsiveness.
Replace 'my-lib' with your actual library and render something from it!
"""
value = param.String(default="Hello")
_importmap = {
"imports": {
# Replace with your actual library
"my-lib": "https://esm.sh/my-lib@1.0.0",
}
}
_esm = """
import myLib from 'my-lib';
export function render({ model, el }) {
// 1. Verify import works
console.log('Library loaded:', myLib);
// 2. Render something from the library!
// Replace this with actual library usage, e.g.:
// - myLib.createChart(el, data)
// - new myLib.Map(el)
// - myLib.render(<Component />, el)
const div = document.createElement('div');
div.id = 'poc-element';
div.textContent = model.value;
// 3. Verify Python-JS sync
model.on('value', () => { div.textContent = model.value; });
// 4. Verify responsive sizing
div.style.cssText = 'width:100%;height:100%;background:#f0f0f0;';
model.on('resize', () => {
console.log('Resize:', el.clientWidth, el.clientHeight);
});
el.appendChild(div);
}
"""
# Test with explicit dimensions first, then responsive
poc = MyComponentPOC(value="Test", height=200, sizing_mode="stretch_width")
poc.servable()

ALWAYS test the UI via Playwright smoke tests! (see details below)

POC validation checklist:

  • [ ] No console errors (especially import/CORS errors)
  • [ ] Library object logs correctly in console
  • [ ] Library renders visible output (chart, map, widget, etc.)
  • [ ] Changing poc.value = "New" updates the display
  • [ ] Component has non-zero dimensions
  • [ ] Resize events fire when browser window changes
Phase 2: Finalize

Once the POC validates all three concerns, build out the full component:

  1. Add all parameters and their JS sync handlers
  2. Implement the full library integration
  3. Add error handling and edge cases
  4. Add CSS styling via _stylesheets

3. Core Patterns (All Component Types)

Python Class Structure

All custom components inherit from a base class and use param for state:

python
import param
from panel.custom import JSComponent # or ReactComponent, AnyWidgetComponent
from pathlib import Path
class MyComponent(JSComponent):
"""A custom component with Python-JS state synchronization."""
# Define parameters that sync with JavaScript
value = param.Integer(default=0, bounds=(0, 100), doc="Current value")
label = param.String(default="Click me", doc="Button label")
# ESM code (inline string or external file)
_esm = Path(__file__).parent / "my_component.js"
# Optional: CDN imports
_importmap = {
"imports": {
"lodash": "https://esm.sh/lodash@4.17.21",
}
}
# Optional: CSS styles
_stylesheets = [
Path(__file__).parent / "my_component.css",
# Or inline CSS string
]
ESM Export Pattern

All component types export a render function:

javascript
// JSComponent / ReactComponent / MaterialUIComponent
export function render({ model, el }) {
// model: access to Python parameters
// el: DOM element to render into
}
// AnyWidgetComponent uses default export
export default {
render({ model, el }) {
// Same signature
}
}
Import Maps for CDN Dependencies
python
_importmap = {
"imports": {
# Basic import
"canvas-confetti": "https://esm.sh/canvas-confetti@1.6.0",
# Namespace import (trailing slash)
"@mui/material/": "https://esm.sh/@mui/material@5.16.7/",
# Shared dependencies with ?external=
"my-react-lib": "https://esm.sh/my-react-lib?external=react,react-dom",
}
}
Child and Children Parameters

Nest Panel components inside custom components:

python
from panel.custom import JSComponent, Child, Children
class Container(JSComponent):
header = Child() # Single child
items = Children() # Multiple children
_esm = """
export function render({ model, el }) {
const header = model.get_child("header");
el.appendChild(header);
for (const item of model.get_child("items")) {
el.appendChild(item);
}
}
"""
Event Handling

JavaScript → Python:

javascript
// In JavaScript
button.onclick = () => {
model.send_event('button_click', { timestamp: Date.now() });
};
python
# In Python
class MyComponent(JSComponent):
def _handle_button_click(self, event):
print(f"Button clicked at {event.data['timestamp']}")

Python → JavaScript:

python
# In Python
class MyComponent(JSComponent):
def trigger_animation(self):
self.send_msg({'action': 'animate', 'duration': 500})
javascript
// In JavaScript
model.on('msg:custom', (event) => {
if (event.data.action === 'animate') {
runAnimation(event.data.duration);
}
});

4. JSComponent Patterns

JSComponent is the foundation for building custom Panel components with vanilla JavaScript. Use it for DOM manipulation, Web Components, and wrapping libraries like D3, Leaflet, or Chart.js.

Basic Structure
python
import param
from panel.custom import JSComponent
class CounterButton(JSComponent):
"""A simple counter button component."""
value = param.Integer(default=0, doc="Current count")
_esm = """
export function render({ model, el }) {
const button = document.createElement('button');
button.id = 'counter-btn';
function update() {
button.textContent = `Count: ${model.value}`;
}
button.onclick = () => {
model.value += 1;
};
model.on('value', update);
update(); // Initialize
el.appendChild(button);
}
"""
State Synchronization

Reading and Writing Parameters:

javascript
// Direct property access
const currentValue = model.value;
const label = model.label;
// Direct assignment syncs to Python
model.value = 42;
model.label = "New Label";

Subscribing to Changes:

javascript
export function render({ model, el }) {
const display = document.createElement('div');
// Subscribe to changes
model.on('value', () => {
display.textContent = model.value;
});
// Initialize with current value
display.textContent = model.value;
el.appendChild(display);
}
Lifecycle Hooks
javascript
// render - Initial render (called once)
export function render({ model, el }) {
// Setup DOM, event listeners
}
// after_render - Post-render (useful for measurements)
export function after_render({ model, el }) {
const { width, height } = el.getBoundingClientRect();
initChart(el, width, height);
}
// resize - Size changes
model.on('resize', ({ width, height }) => {
canvas.width = width;
canvas.height = height;
redraw();
});
// remove - Cleanup
model.on('remove', () => {
clearInterval(interval);
document.removeEventListener('keypress', handler);
});
External Libraries Example (D3)
python
class D3BarChart(JSComponent):
data = param.List(default=[10, 20, 30, 40, 50])
_importmap = {
"imports": {
"d3": "https://esm.sh/d3@7"
}
}
_esm = """
import * as d3 from 'd3';
export function render({ model, el }) {
const svg = d3.select(el)
.append('svg')
.attr('width', 400)
.attr('height', 200);
function update() {
const bars = svg.selectAll('rect').data(model.data);
bars.enter()
.append('rect')
.merge(bars)
.attr('x', (d, i) => i * 50)
.attr('y', d => 200 - d * 3)
.attr('width', 40)
.attr('height', d => d * 3)
.attr('fill', 'steelblue');
bars.exit().remove();
}
model.on('data', update);
update();
}
"""

4.1. Wrapping Third-Party Web Components

When wrapping existing web components, follow these patterns:

Custom Element Lifecycle

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
30
Repository forks
13
7-day trend score
17

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 4 Apr 2026, 7 months ago.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/marcskovmadsen/holoviz-mcp/panel-custom-components/badge)](https://verified-skill.com/skills/marcskovmadsen/holoviz-mcp/panel-custom-components)

Something wrong with this skill or its page? Tell us.